Skip to content

Latest commit

 

History

History
813 lines (611 loc) · 19.8 KB

class-ProcessPool.md

File metadata and controls

813 lines (611 loc) · 19.8 KB
Asyncpal API Reference

Home | Project | Module | Source

Class ProcessPool

Module: asyncpal.__init__

Class: ProcessPool

Inheritance: asyncpal.pool.Pool

The ProcessPool class for parallelism.

Fields table

Here are fields exposed in the class:

Field Value
_abc_impl <_abc_data object at 0x7f7882637570>

Back to top

Properties table

Here are properties exposed in the class:

Property Methods Description
cancelled_tasks getter No docstring.
final_args getter No docstring.
final_kwargs getter No docstring.
finalizer getter No docstring.
idle_timeout getter, setter No docstring.
init_args getter No docstring.
init_kwargs getter No docstring.
initializer getter No docstring.
is_broken getter No docstring.
is_closed getter No docstring.
is_terminated getter No docstring.
max_tasks_per_worker getter No docstring.
max_workers getter No docstring.
mp_context getter No docstring.
name getter No docstring.
worker_type getter No docstring.
workers getter No docstring.

Back to top

Methods within class

Here are methods exposed in the class:

__init__

Initialization.

def __init__(self, max_workers=None, *, name='ProcessPool', idle_timeout=60, initializer=None, init_args=None, init_kwargs=None, finalizer=None, final_args=None, final_kwargs=None, max_tasks_per_worker=None, mp_context=None):
    ...
Parameter Description
max_workers the maximum number of workers. Defaults to CPU count. On Windows, the maximum number that is accepted for the max_workers is 60.
name the name of the pool. Defaults to the class name
idle_timeout None or a timeout value in seconds. The idle timeout tells how much time an inactive worker can sleep before it closes. This helps the pool to shrink when there isn't much of tasks. If you set None, the pool will never shrink. each worker before it closes
initializer a function that will get called at the start of each worker
init_args arguments (list) to pass to the initializer
init_kwargs keyword arguments (dict) to pass to the initializer
finalizer a function that will get called when the worker is going to close
final_args arguments (list) to pass to the finalizer
final_kwargs keyword arguments (dict) to pass to the finalizer
max_tasks_per_worker Maximum number of tasks a worker is allowed to do before it closes.
mp_context the multiprocessing context. Defaults to multiprocessing.get_context("spawn")

Back to top

check

Check the pool

def check(self):
    ...

Exceptions table

The table below outlines exceptions that may occur.

Exception Circumstance
RuntimeError raised if the pool is closed
BrokenPoolError raised if the pool is broken

Back to top

count_busy_workers

Returns the number of busy workers

def count_busy_workers(self):
    ...

Back to top

count_free_workers

Returns the number of free workers

def count_free_workers(self):
    ...

Back to top

count_pending_tasks

Returns the number of pending tasks

def count_pending_tasks(self):
    ...

Back to top

count_workers

Returns the number of workers that are alive

def count_workers(self):
    ...

Back to top

join

Join the workers, i.e., wait for workers to end their works, then close them

def join(self, timeout=None):
    ...
Parameter Description
timeout None or a number representing seconds.

Exceptions table

The table below outlines exceptions that may occur.

Exception Circumstance
RuntimeError raised when timeout expires

Back to top

map

Perform a Map operation lazily and return an iterator that iterates over the results. Beware, a remote exception will be reraised here

def map(self, target, *iterables, chunk_size=1, buffer_size=1, keep_order=True, timeout=None):
    ...
Parameter Description
target callable
iterables iterables to pass to the target
chunk_size max length for a chunk
buffer_size the buffer_size. A bigger size will consume more memory but the overall operation will be faster
keep_order whether the original order should be kept or not
timeout None or a timeout (int or float) value in seconds

Value to return

Returns an iterator

Exceptions table

The table below outlines exceptions that may occur.

Exception Circumstance
RuntimeError raised when the pool is closed
BrokenPoolError raised when the pool is broken
Exception any remote exception

Back to top

map_all

Perform a Map operation eagerly and return an iterator that iterates over the results. Using this method instead of the map method might cause high memory usage. Beware, a remote exception will be reraised here

def map_all(self, target, *iterables, chunk_size=1, keep_order=True, timeout=None):
    ...
Parameter Description
target callable
iterables iterables to pass to the target
chunk_size max length for a chunk
keep_order whether the original order should be kept or not
timeout None or a timeout (int or float) value in seconds

Value to return

Returns an iterator that iterates over the results.

Exceptions table

The table below outlines exceptions that may occur.

Exception Circumstance
RuntimeError raised when the pool is closed
BrokenPoolError raised when the pool is broken
Exception any remote exception

Back to top

map_all_unordered

Same as map with 'keep_order' set to False

def map_all_unordered(self, target, *iterables, chunk_size=1, timeout=None):
    ...

Back to top

map_unordered

Same as map with 'keep_order' set to False

def map_unordered(self, target, *iterables, chunk_size=1, buffer_size=1, timeout=None):
    ...

Back to top

run

Submit the task to the pool, and return the result (or re-raise the exception raised by the callable)

def run(self, target, /, *args, **kwargs):
    ...
Parameter Description
target callable
args args to pass to the callable
kwargs kwargs to pass to the callable

Exceptions table

The table below outlines exceptions that may occur.

Exception Circumstance
RuntimeError raised when the pool is closed
BrokenPoolError raised when the pool is broken
Exception exception that might be raised by the task itself

Back to top

shutdown

Close the pool by joining workers and cancelling pending tasks. Note that cancelled tasks can be retrieved via the cancelled_tasks property.

def shutdown(self):
    ...

Value to return

Returns False if the pool has already been closed, else returns True.

Back to top

spawn_max_workers

Spawn the maximum number of workers

def spawn_max_workers(self):
    ...

Back to top

spawn_workers

Spawn a specific number of workers or the right number of workers that is needed

def spawn_workers(self, n=None):
    ...
Parameter Description
n None or an integer.

Value to return

Returns the number of spawned workers

Back to top

starmap

Perform a Starmap operation lazily and return an iterator that iterates over the results. Beware, a remote exception will be reraised here

def starmap(self, target, iterable, chunk_size=1, buffer_size=1, keep_order=True, timeout=None):
    ...
Parameter Description
target callable
iterable sequence of args to pass to the target
chunk_size max length for a chunk
buffer_size the buffer_size. A bigger size will consume more memory but the overall operation will be faster
keep_order whether the original order should be kept or not
timeout None or a timeout (int or float) value in seconds

Value to return

Returns an iterator that iterates over the results.

Exceptions table

The table below outlines exceptions that may occur.

Exception Circumstance
RuntimeError raised when the pool is closed
BrokenPoolError raised when the pool is broken
Exception any remote exception

Back to top

starmap_all

Perform a Starmap operation eagerly and return an iterator that iterates over the results. Using this method instead of the map method might cause high memory usage. Beware, a remote exception will be reraised here

def starmap_all(self, target, iterable, chunk_size=1, keep_order=True, timeout=None):
    ...
Parameter Description
target callable
iterable sequence of args to pass to the target
chunk_size max length for a chunk
keep_order whether the original order should be kept or not
timeout None or a timeout (int or float) value in seconds

Value to return

Returns an iterator that iterates over the results.

Exceptions table

The table below outlines exceptions that may occur.

Exception Circumstance
RuntimeError raised when the pool is closed
BrokenPoolError raised when the pool is broken
Exception any remote exception

Back to top

starmap_all_unordered

Same as starmap_all with 'keep_order' set to False

def starmap_all_unordered(self, target, iterable, chunk_size=1, timeout=None):
    ...

Back to top

starmap_unordered

Same as starmap with 'keep_order' set to False

def starmap_unordered(self, target, iterable, chunk_size=1, buffer_size=1, timeout=None):
    ...

Back to top

submit

Submit the task to the pool, and return a future object

def submit(self, target, /, *args, **kwargs):
    ...
Parameter Description
target callable
args args to pass to the callable
kwargs kwargs to pass to the callable

Exceptions table

The table below outlines exceptions that may occur.

Exception Circumstance
RuntimeError raised when the pool is closed
BrokenPoolError raised when the pool is broken
Exception exception that might be raised by the task itself

Back to top

test

Test the pool by creating another pool with the same config and doing some computation on it to ensure that it won't break. This method might raise a BrokenPoolError exception

def test(self):
    ...

Back to top

_cancel_tasks

No docstring

def _cancel_tasks(self):
    ...

Back to top

_cleanup_stored_futures

No docstring

def _cleanup_stored_futures(self):
    ...

Back to top

_cleanup_task_queue

No docstring

def _cleanup_task_queue(self):
    ...

Back to top

_consume_message_queue

No docstring

def _consume_message_queue(self):
    ...

Back to top

_count_busy_workers

No docstring

def _count_busy_workers(self):
    ...

Back to top

_count_free_workers

No docstring

def _count_free_workers(self):
    ...

Back to top

_count_pending_tasks

No docstring

def _count_pending_tasks(self):
    ...

Back to top

_count_workers

No docstring

def _count_workers(self):
    ...

Back to top

_create_lock

No docstring

def _create_lock(self):
    ...

Back to top

_create_worker

No docstring

def _create_worker(self):
    ...

Back to top

_drain_mp_task_queue

No docstring

def _drain_mp_task_queue(self):
    ...

Back to top

_drain_task_queue

No docstring

def _drain_task_queue(self):
    ...

Back to top

_ensure_pool_integrity

No docstring

def _ensure_pool_integrity(self):
    ...

Back to top

_filter_tasks

No docstring

def _filter_tasks(self):
    ...

Back to top

_join_inactive_workers

No docstring

def _join_inactive_workers(self):
    ...

Back to top

_join_workers

No docstring

def _join_workers(self, timeout=None):
    ...

Back to top

_map_eager

No docstring

def _map_eager(self, target, iterable, keep_order, timeout):
    ...

Back to top

_map_eager_chunked

No docstring

def _map_eager_chunked(self, target, iterable, chunk_size, keep_order, timeout):
    ...

Back to top

_map_lazy

No docstring

def _map_lazy(self, target, iterable, buffer_size, timeout):
    ...

Back to top

_map_lazy_chunked

No docstring

def _map_lazy_chunked(self, target, iterable, chunk_size, buffer_size, timeout):
    ...

Back to top

_map_lazy_chunked_unordered

No docstring

def _map_lazy_chunked_unordered(self, target, iterable, chunk_size, buffer_size, timeout):
    ...

Back to top

_map_lazy_unordered

No docstring

def _map_lazy_unordered(self, target, iterable, buffer_size, timeout):
    ...

Back to top

_notify_workers_to_shutdown

No docstring

def _notify_workers_to_shutdown(self):
    ...

Back to top

_on_worker_exception

No docstring

def _on_worker_exception(self, worker_id, exc):
    ...

Back to top

_on_worker_shutdown

No docstring

def _on_worker_shutdown(self, worker_id):
    ...

Back to top

_setup

No docstring

def _setup(self):
    ...

Back to top

_shutdown_filter_thread

No docstring

def _shutdown_filter_thread(self):
    ...

Back to top

_shutdown_message_thread

No docstring

def _shutdown_message_thread(self):
    ...

Back to top

_spawn_filter_thread

No docstring

def _spawn_filter_thread(self):
    ...

Back to top

_spawn_message_thread

No docstring

def _spawn_message_thread(self):
    ...

Back to top

_spawn_workers

No docstring

def _spawn_workers(self, n=None):
    ...

Back to top

_submit_task

No docstring

def _submit_task(self, target, *args, **kwargs):
    ...

Back to top

_update_future

No docstring

def _update_future(self, message):
    ...

Back to top