[Twisted-Python] Sequential use of asynchronous calls

Maarten ter Huurne maarten at treewalker.org
Sat May 26 10:45:21 MDT 2007


On Saturday 26 May 2007, Ed Suominen wrote:

> http://foss.eepatents.com/api/twisted-goodies/taskqueue.base.TaskQueue.html

That looks interesting, but I don't think it has the same purpose.

If I understand it correctly, TaskQueue dispatches synchronous calls to a pool 
of workers. The thing I posted runs a series of asynchronous calls in 
succession. In other words, TaskQueue handles callables, while "@sequential" 
handles Deferreds.

Also, TaskQueue seems to be designed for running a number of indepedent tasks, 
while "@sequential" is designed for situations in which call n+1 depends on 
the result of call n. The added value of "@sequential" is that you don't have 
to deal with Deferreds yourself, but can use the return value of the yield 
instead (or the exception thrown by it).

The original example did not demonstrate using the result of a previous call 
in the next call. Here is a new implementation of the "work" method which 
does:

===
@sequential
def work():
    value = 9
    try:
        while True:
            print value
            value = (yield getDummyData(value)) - 20
    except ValueError, e:
        print 'failed:', e
===

Bye,
		Maarten
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: </pipermail/twisted-python/attachments/20070526/6fa149c5/attachment.sig>


More information about the Twisted-Python mailing list