Package twisted :: Package flow :: Module threads :: Class Threaded
[show private | hide private]
[frames | no frames]

Class Threaded

Instruction --+    
              |    
          Stage --+
                  |
                 Threaded


A stage which runs a blocking iterable in a separate thread

This stage tunnels output from an iterable executed in a separate
thread to the main thread.   This process is carried out by 
a result buffer, and returning Cooperate if the buffer is
empty.   The wrapped iterable's __iter__ and next() methods
will only be invoked in the spawned thread.

This can be used in one of two ways, first, it can be 
extended via inheritance; with the functionality of the
inherited code implementing next(), and using init() for
initialization code to be run in the thread.

If the iterable happens to have a chunked attribute, and
that attribute is true, then this wrapper will assume that
data arrives in chunks via a sequence instead of by values.

    def runInThread(cnt):
        while cnt > 0:
           from time import sleep
           sleep(.1)
           yield cnt
           cnt -= 1
    
    def howdy():
        print "howdy"
    
    source = flow.Threaded(runInThread(8))
    reactor.callLater(.3,howdy)
    printFlow(source)

Method Summary
  __init__(self, iterable, *trap)
  __iter__(self)
(inherited from Stage)
  next(self)
return current result (inherited from Stage)

Class Variable Summary
class Instruction

Class Variable Details

Instruction

Instruction = twisted.flow.threads.Instruction

Generated by Epydoc 1.1 on Fri Jun 27 03:45:28 2003 http://epydoc.sf.net