class documentation

class callback_iter: (source)

View In Hierarchy

Convert a function that uses callbacks to an iterator. Let *func* be a function that takes a `callback` keyword argument. For example: >>> def func(callback=None): ... for i, c in [(1, 'a'), (2, 'b'), (3, 'c')]: ... if callback: ... callback(i, c) ... return 4 Use ``with callback_iter(func)`` to get an iterator over the parameters that are delivered to the callback. >>> with callback_iter(func) as it: ... for args, kwargs in it: ... print(args) (1, 'a') (2, 'b') (3, 'c') The function will be called in a background thread. The ``done`` property indicates whether it has completed execution. >>> it.done True If it completes successfully, its return value will be available in the ``result`` property. >>> it.result 4 Notes: * If the function uses some keyword argument besides ``callback``, supply *callback_kwd*. * If it finished executing, but raised an exception, accessing the ``result`` property will raise the same exception. * If it hasn't finished executing, accessing the ``result`` property from within the ``with`` block will raise ``RuntimeError``. * If it hasn't finished executing, accessing the ``result`` property from outside the ``with`` block will raise a ``more_itertools.AbortThread`` exception. * Provide *wait_seconds* to adjust how frequently the it is polled for output.

Method __enter__ Undocumented
Method __exit__ Undocumented
Method __init__ Undocumented
Method __iter__ Undocumented
Method __next__ Undocumented
Property done Undocumented
Property result Undocumented
Method _reader Undocumented
Instance Variable _aborted Undocumented
Instance Variable _callback_kwd Undocumented
Instance Variable _executor Undocumented
Instance Variable _func Undocumented
Instance Variable _future Undocumented
Instance Variable _iterator Undocumented
Instance Variable _wait_seconds Undocumented
def __enter__(self): (source)

Undocumented

def __exit__(self, exc_type, exc_value, traceback): (source)

Undocumented

def __init__(self, func, callback_kwd='callback', wait_seconds=0.1): (source)

Undocumented

def __iter__(self): (source)

Undocumented

def __next__(self): (source)

Undocumented

Undocumented

Undocumented

def _reader(self): (source)

Undocumented

_aborted: bool = (source)

Undocumented

_callback_kwd = (source)

Undocumented

_executor = (source)

Undocumented

Undocumented

Undocumented

_iterator = (source)

Undocumented

_wait_seconds = (source)

Undocumented