asynqueue.threads.ThreadLooper(object)
class documentation
Part of asynqueue.threads
(View In Hierarchy)
I run function calls in a dedicated thread.
Each call returns a Deferred
to its eventual result, which
is a 2-tuple containing the status of the last call and its result
according to the format of util.CallRunner
.
If the result is an iterable other than one of Python's built-in ones,
the Deferred
fires with an instance of iteration.Prefetcherator
instead. Couple it to your own deferator to iterate over the underlying
iterable running in my thread. You can disable this behavior by setting
raw=True
in the constructor, or enable/disable it on an
individual call by setting raw=True/False.
Parameters | raw | Set True to have calls return (deferred) iterators rather than
instances of Prefetcherator . |
Instance Variable | timeout | The wait timeout, which defaults to 60 (one minute). This is just how long the thread loop waits before checking for a pending deferred and firing it with a timeout error. Otherwise, it simply waits another minute, and it can do that forever with no problem. |
Method | __init__ | ThreadLooper (raw=False) |
Method | loop | Runs a loop in a dedicated thread that waits for new tasks. The loop
exits when a None object is supplied as a task. |
Method | call | Runs the supplied callable function with any args and keywords in a
dedicated thread, returning a Deferred that fires with a
status/result tuple. |
Method | dr2ip | Converts a Deferator into
an iteration.IterationProducer ,
with a consumer registered if you supply one. |
Method | deferToThread | My single-threaded, queued, doNext-able, Deferator-able answer to Twisted's deferToThread. |
Method | stop | Returns a Deferred that fires when all tasks and instances
of Deferator
are done, the task loop has ended, and its thread has terminated. |
Runs a loop in a dedicated thread that waits for new tasks. The loop
exits when a None
object is supplied as a task.
def call(self, f, *args, **kw):
Runs the supplied callable function with any args and keywords in a
dedicated thread, returning a Deferred
that fires with a
status/result tuple.
Calls are done in the order received, unless you set
doNext=True
.
Set raw=True
to have a raw iterator returned instead of a
Deferator, or raw=False
to have a Deferator
returned instead of a raw iterator, contrary to the instance-wide default
set with the constructor keyword 'raw'.
Converts a Deferator
into
an iteration.IterationProducer
,
with a consumer registered if you supply one.
Then each iteration will be written to your consumer, and the deferred
returned will fire when the iterations are done. Otherwise, the deferred
will fire with an iteration.IterationProducer
and you will have to register with and run it yourself.
My single-threaded, queued, doNext-able, Deferator-able answer to Twisted's deferToThread.
If you expect a deferred iterator as your result (an instance of iteration.Deferator
),
supply an IConsumer
implementor via the consumer
keyword. Each iteration will be written to it, and the deferred will fire
when the iterations are done. Otherwise, unless the raw option has
been set True
in my constructor or as a keyword to this call,
the deferred will fire with an iteration.Deferator
.
Returns a Deferred
that fires when all tasks and instances
of Deferator
are done, the task loop has ended, and its thread has terminated.