asynqueue.threads.IterationGetter(PoolUser)
class documentation
Part of asynqueue.threads
(View In Hierarchy)
Known subclasses: asynqueue.test.test_threads.TestableIterationGetter, asynqueue.threads.Consumerator, asynqueue.threads.Filerator
Abstract base class for objects that munch data on one end and act like iterators to yield it on the other end.
See Also | Consumerator
and Filerator . |
Class | IterationStopper | Undocumented |
Method | __init__ | IterationGetter(maxThreads=None) |
Method | start | Call this when I should start listening for iterations. |
Method | loop | Override this method to generate a value for my iterations. The method must be synchronized with a series of locking primitives: |
Method | deferUntilDone | Returns a Deferred that fires when I am done iterating. |
Method | __iter__ | Undocumented |
Method | __next__ | Undocumented |
Inherited from PoolUser:
Class Method | setup | Sets up stuff class-wide, with all the potential pitfalls that entails. |
Class Method | shutdown | Shuts down all threads, returning a Deferred that fires
when everything's done, class-wide. |
Class Method | deferToThreadInPool | Runs the f-args-kw call combo in one of my threads,
returning a Deferred that fires with the eventual result. Can
be run from the class or any instance of me with the exact same result. |
Method | pool | Returns a reference to the class-wide threadpool, starting it if this is the first time it's been used. |
IterationGetter(maxThreads=None)
Call this when I should start listening for iterations.
Sets up locks for my iteration-consuming thread (from my
ThreadPool
), the blocking-iterator thread, and the
next-iteration event. Lock both of my iteration-processing loops until an
iteration is received, but leaves the next-iteration lock nLock
unlocked. The iteration-consuming thread will lock it to overwrite the
blocking-iterator thread's value of each iteration.
Calls my subclass's loop
method in its own thread. If too many threads are currently open, queues
the loop call until one finishes up in some other instance of me.
Override this method to generate a value for my iterations. The method must be synchronized with a series of locking primitives:
-
First, wait to acquire cLock. This will be released when a value
has been given to my subclass instance, e.g., through its
write
method. At this point, you can retrieve the value and let your value provider know it is free to provide more. -
Then wait to acquire nLock. This will be released when the
next
method has obtained its next iteration value from bIterationValue. At this point, overwrite bIterationValue with the new value you've just obtained, or with an instance ofIterationStopper
if iteration is done. -
Release bLock to let the
next
loop know it can process the next iteration value (or iteration stopper) now in bIterationValue.
See Also | Consumerator.loop
and Filerator.loop |