navigate.model.concurrency.concurrency_tools.ObjectInSubprocess
- class navigate.model.concurrency.concurrency_tools.ObjectInSubprocess(initializer, *initargs, custom_loop=None, close_method_name=None, closeargs=None, closekwargs=None, with_lock=False, **initkwargs)
Bases:
object- __init__(initializer, *initargs, custom_loop=None, close_method_name=None, closeargs=None, closekwargs=None, with_lock=False, **initkwargs)
Make an object in a child process, that acts like it isn’t.
As much as possible, we try to make instances of ObjectInSubprocess behave as if they’re an instance of the object living in the parent process. They’re not, of course: they live in a child process. If you have spare cores on your machine, this turns CPU-bound operations (which threading can’t parallelize) into IO-bound operations (which threading CAN parallelize), without too much mental overhead for the coder.
- Parameters:
initializer (callable) – Callable that returns an instance of a Python object.
*initargs (tuple) – Positional arguments to
initializer.custom_loop (callable, optional) – Child-process loop to use instead of the default message loop.
close_method_name (str, optional) – Name of the object’s method to call when the child process exits.
closeargs (tuple, optional) – Positional arguments to the close method.
closekwargs (dict, optional) – Keyword arguments to the close method.
with_lock (bool, optional) – Whether to create a resource lock for this subprocess.
**initkwargs (dict) – Keyword arguments to
initializer.
Methods
__init__(initializer, *initargs[, ...])Make an object in a child process, that acts like it isn't.