<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Thanks Pablo!<br>
this looks pretty clear and neat, I'll try it out.<br>
<br>
Just one newbie question - is the "_"&nbsp; in "acquire_cb(_)"&nbsp; just a
placeholder for my own parameters, or does it have an actual meaning?<br>
I've never seen this done in python before, and couldn't find other
examples for it online...<br>
<br>
Cheers,<br>
Nadav<br>
<br>
<br>
Pablo Mart&iacute; wrote:
<blockquote cite="mid:1189755451.12076.16.camel@satellite" type="cite">
  <pre wrap="">On Fri, 2007-09-14 at 00:58 -0400, Nadav Aharony wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">Hi, 

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.
    </pre>
  </blockquote>
  <pre wrap=""><!---->
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.
  </pre>
  <pre wrap=""><!---->
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()
        self.check_queue()

    def check_queue(self):
        self.queue.get().addCallback(self._process_one)
    
    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
            pass

        self.lock.acquire().addCallback(acquire_cb)

    def queue_petition(self, petition):
        self.queue.put(petition)
        return petition.deferred

Regards,
Pablo
  </pre>
  <pre wrap=""><!---->


_______________________________________________
Twisted-Python mailing list
<a class="moz-txt-link-abbreviated"
 href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a>
<a class="moz-txt-link-freetext"
 href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a>
  </pre>
</blockquote>
<br>
</body>
</html>