[Twisted-Python] Transmit queue - how would I go at it?

Nadav Aharony nadav at MIT.EDU
Fri Sep 14 00:58:12 EDT 2007


I am working on an application where clients request files, and since 
each file is very large, the server ACKs the requests and then queues 
them to be served later, one at a time.
I am relatively new to Twisted and was wondering what would be the best 
way to approach this.

Here is what I came up with so far:

1) Use Deferred callbacks, and string together callbacks to a "file 
sender" function - once a file is sent, the function is called back with 
a pointer to the next file in line.
If I do so - is there some automatic garbage collection of the callbacks 
that have already been handled? (there may eventually be hundreds of 
files to be sent)
In this approach, would there be a natural way to check if a new request 
is actually a repeat of a previous request already queued?

2) Use some type of queue - where each new file request is queued, and 
some single function handles them one at at time (I guess with 
asynchronous callbacks to itself every time the transport layer is free 
to send another file and the queue is not empty).
Is there some queue structure like this in Twisted? I saw something 
called a DefferedQueue but could not find many examples or documentation 
about it and about its usage.

I mainly want to understand, from the "Twisted mindset"  which would be 
the the right way to go?
Also, say in the future I would want to implement priority queuing and 
handling of the requests rather than a FIFO - how would I do that in 

Any thoughts and/or code examples would be greatly appreciated

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20070914/3ea09a9c/attachment.htm 

More information about the Twisted-Python mailing list