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.

ParametersrawSet 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.
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.
def __init__(self, raw=False):

ThreadLooper(raw=False)

def loop(self):

Runs a loop in a dedicated thread that waits for new tasks. The loop exits when a None object is supplied as a task.

@defer.inlineCallbacks
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'.

def dr2ip(self, dr, consumer=None):

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.

def deferToThread(self, f, *args, **kw):

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.

def stop(self):

Returns a Deferred that fires when all tasks and instances of Deferator are done, the task loop has ended, and its thread has terminated.

API Documentation for AsynQueue, generated by pydoctor at 2022-11-17 13:13:24.