[Twisted-Python] Re: Re: rewrite of flow.py completed
Philippe Lafoucrière
lafou at wanadoo.fr
Tue Apr 15 07:21:55 EDT 2003
> class CountIterator(flow.ThreadedIterator):
> def __init__(self, count):
> flow.ThreadedIterator.__init__(self)
> self.count = count
> def next(self): # this is run in a separate thread
> from time import sleep
> sleep(.1)
> val = self.count
> if not(val):
> raise flow.StopIteration
> self.count -= 1
> return [val]
> def res(x): assert([5,4,3,2,1] == x)
> from twisted.internet import reactor
> f = flow.DeferredFlow(CountIterator(5))
> f.addCallback(res)
> reactor.callLater(2,reactor.stop)
> reactor.run()
>
This doen't work
here's the real result : [[5], [4], [3], [2], [1]]
>python -u test_flow2.py
[[5], [4], [3], [2], [1]]
Traceback (most recent call last):
File "/home/gravis/src/python/cvs/Twisted/twisted/internet/base.py", line
358, in runUntilCurrent
call.func(*call.args, **call.kw)
File "flow.py", line 215, in _execute
self.callback(self.results)
File "/home/gravis/src/python/cvs/Twisted/twisted/internet/defer.py", line
193, in callback
self._startRunCallbacks(result, 0)
File "/home/gravis/src/python/cvs/Twisted/twisted/internet/defer.py", line
249, in _startRunCallbacks
self._runCallbacks()
--- <exception caught here> ---
File "/home/gravis/src/python/cvs/Twisted/twisted/internet/defer.py", line
262, in _runCallbacks
self.result = callback(self.result, *args, **kw)
File "test_flow2.py", line 16, in res
def res(x): print x; assert([5,4,3,2,1] == x)
exceptions.AssertionError:
>Exit code: 0
More information about the Twisted-Python
mailing list