[Twisted-Python] Transmit queue - how would I go at it?
nadav at MIT.EDU
Sat Sep 15 23:36:37 EDT 2007
this looks pretty clear and neat, I'll try it out.
Just one newbie question - is the "_" in "acquire_cb(_)" just a
placeholder for my own parameters, or does it have an actual meaning?
I've never seen this done in python before, and couldn't find other
examples for it online...
Pablo Martí wrote:
> On Fri, 2007-09-14 at 00:58 -0400, Nadav Aharony wrote:
>> 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.
> Hi Nadav,
> I had a similar requirement with my application. You must offer an
> asynchronous interface while dealing with each request synchronously. I
> think that you should push your requests to a
> twisted.internet.defer.DeferredQueue and process one at a time with the
> aid of twisted.internet.defer.DeferredLock.
> If we consider that each of your petitions has an associated deferred
> that will be called back when its finished:
> (I haven't run this)
> from twisted.internet import defer
> class OneAtATime(object):
> def __init__(self):
> super(OneAtATime, self).__init__()
> self.queue = defer.DeferredQueue()
> self.lock = defer.DeferredLock()
> def check_queue(self):
> def _process_one(self, petition):
> def acquire_cb(_):
> # do whatever with your petition
> # make sure that when you're done you call
> # self.lock.release() and self.check_queue()
> # on a state machine, this would be while transitioning
> # to the "idle" state
> def queue_petition(self, petition):
> return petition.deferred
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Twisted-Python