Skip to main content

Multiprocessing controllable pool

Project description

controlpool

Multiprocessing controllable pool

Pool

Pool(func, processes, * [, worker_params, marks, raise_if_fail, controller])

Class that create pool of workers for parrllel calculations.

func

Callable obect, that call on every task. Signature func(worker_param, arg) if worker_params is set or func(arg). Here arg is argument of Calculation from map args, worker_param is parameter of worker from worker_params.

processes

Number of processes for parralel calculation. Actiual number of worker is minumum of processes, length of worker_params (if set) and length of marks (if set).

Type: int

worker_params

Iterables that represent list of workers parameters. Parameter of worker pass to func. If worker_params is not set othing is pass to func.

marks

Same as worker_params, but not pass to func. May be accesed by mark attribute of WorkerInfo. If marks is not set None assigned as mark for each worker.

raise_if_fail

If True raise exception if all workers raise exeption. If *False nothing happen in this case (pool wait for new worker).

Type: bool

Default: True

controller

Callable object that run in separate process and may controll pool workflow. controller call with single argument of ControllerTerminal instance. If not set, it will be no controller process.

map

Pool.map(args, return_arg=False)

Start parallel applies on func on args.

If one of worker faild (raise exception), Pool try to reasigne this task to another worker.

Return list of results (if return_arg is false) o list of tuples (argument, result) (if return_arg is true) in same order, as in args.

args

Iterable.

map_iterable

Pool.map_iterable(args, return_arg=False)

Same as map but return generator instead of list.

close

Pool.close()

Free pool resource. It should be called after all calculations done. Alternatively Pool may be used as context manager.

ControllerTerminal

Class for comunicate with poll. Instance of this class pass to controller function. There is no reason to create instace manually.

get_info

ControllerTerminal.get_info()

Return information about Pool. See Info.

add_worker

ControllerTerminal.add_worker([mark, worker_param])

Add worker to Pool.

Return (error, error_explanation). If error is True (or dequivalent), error_explanation contain text explanation of eror.

mark

Set mark of worker.

Default: None

worker_param

Set parameter of worker.

Default: None

change_worker_state

ControllerTerminal.change_worker_state(worker_id, state [, now])

Change state of existing worker in Pool.

Return (error, error_explanation). If error is True (or dequivalent), error_explanation contain text explanation of eror.

worker_id

Order number (starting with 0) in list of workers in pool.

state

New state of worker (see WorkerState).

now

Indicate that state changed immediately (True) or after worker has completed current task.

Default: False

Type Bool

Info

Class represent information about Pool. Contain several attributes:

workers_info

List of WorkerInfo. Each element represents info about each worker. Order number in list represent worker ID.

workers_info

Number of complete tasks.

delayed_tasks

Number of task pending to reasign to another worker (see map).

WorkerInfo

Class represent information about worker. Contain several attributes:

mark

Mark of the worker.

state

state of worker (see WorkerState).

task

Current task

exception

Exception that raise worker. None if there is no exception.

worker_param

Parameter of worker. Present only if there was worker_params in Pool.

WorkerState

Class-enumerator represent worker state. There is several state:

RUN

Worker do calculation

PAUSED

Worker paused by pool (not by controller). Not available form controller.

STOPPED

Worker stopped by controller.

EXCEPTION

Worker raise exeption. Not available form controller.

KILLED

Worker completely killed.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

controlpool-0.4.0.tar.gz (23.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

controlpool-0.4.0-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

File details

Details for the file controlpool-0.4.0.tar.gz.

File metadata

  • Download URL: controlpool-0.4.0.tar.gz
  • Upload date:
  • Size: 23.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for controlpool-0.4.0.tar.gz
Algorithm Hash digest
SHA256 cb339bb8f8d969360a4d1451da72883ff2da3daffabe725f24ebd752771e7d3e
MD5 baacf26f24f7b825a8ffc95b6f7291e3
BLAKE2b-256 aa80043d8f99629ef9bb40f7375a50c40ab526e71fead59f5eebfb9c10949a54

See more details on using hashes here.

File details

Details for the file controlpool-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: controlpool-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 20.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for controlpool-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f881a7c1470a963ed99f5a578427097a4c0f1ad8d5c3de59b214c91da9191eb7
MD5 eaee90bdc9886630795ac02c3d543ba0
BLAKE2b-256 e97346411fafaaf2959986ace22f42e5286df4647fbccac7246700f7eee9e4ee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page