Skip to main content

better multiprocessing and multithreading in Python

Project description

About Multiprocess

multiprocess is a fork of multiprocessing. multiprocess extends multiprocessing to provide enhanced serialization, using dill. multiprocess leverages multiprocessing to support the spawning of processes using the API of the Python standard library’s threading module. multiprocessing has been distributed as part of the standard library since Python 2.6.

multiprocess is part of pathos, a Python framework for heterogeneous computing. multiprocess is in active development, so any user feedback, bug reports, comments, or suggestions are highly appreciated. A list of issues is located at https://github.com/uqfoundation/multiprocess/issues, with a legacy list maintained at https://uqfoundation.github.io/project/pathos/query.

Major Features

multiprocess enables:

  • objects to be transferred between processes using pipes or multi-producer/multi-consumer queues

  • objects to be shared between processes using a server process or (for simple data) shared memory

multiprocess provides:

  • equivalents of all the synchronization primitives in threading

  • a Pool class to facilitate submitting tasks to worker processes

  • enhanced serialization, using dill

Current Release

The latest released version of multiprocess is available from:

https://pypi.org/project/multiprocess

multiprocess is distributed under a 3-clause BSD license, and is a fork of multiprocessing.

Development Version

You can get the latest development version with all the shiny new features at:

https://github.com/uqfoundation

If you have a new contribution, please submit a pull request.

Installation

multiprocess can be installed with pip:

$ pip install multiprocess

For Python 2, a C compiler is required to build the included extension module from source. Python 3 and binary installs do not require a C compiler.

Requirements

multiprocess requires:

  • python (or pypy), >=3.8

  • setuptools, >=42

  • dill, >=0.3.8

Basic Usage

The multiprocess.Process class follows the API of threading.Thread. For example

from multiprocess import Process, Queue

def f(q):
    q.put('hello world')

if __name__ == '__main__':
    q = Queue()
    p = Process(target=f, args=[q])
    p.start()
    print (q.get())
    p.join()

Synchronization primitives like locks, semaphores and conditions are available, for example

>>> from multiprocess import Condition
>>> c = Condition()
>>> print (c)
<Condition(<RLock(None, 0)>), 0>
>>> c.acquire()
True
>>> print (c)
<Condition(<RLock(MainProcess, 1)>), 0>

One can also use a manager to create shared objects either in shared memory or in a server process, for example

>>> from multiprocess import Manager
>>> manager = Manager()
>>> l = manager.list(range(10))
>>> l.reverse()
>>> print (l)
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
>>> print (repr(l))
<Proxy[list] object at 0x00E1B3B0>

Tasks can be offloaded to a pool of worker processes in various ways, for example

>>> from multiprocess import Pool
>>> def f(x): return x*x
...
>>> p = Pool(4)
>>> result = p.map_async(f, range(10))
>>> print (result.get(timeout=1))
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

When dill is installed, serialization is extended to most objects, for example

>>> from multiprocess import Pool
>>> p = Pool(4)
>>> print (p.map(lambda x: (lambda y:y**2)(x) + x, xrange(10)))
[0, 2, 6, 12, 20, 30, 42, 56, 72, 90]

More Information

Probably the best way to get started is to look at the documentation at http://multiprocess.rtfd.io. Also see multiprocess.tests for scripts that demonstrate how multiprocess can be used to leverge multiple processes to execute Python in parallel. You can run the test suite with python -m multiprocess.tests. As multiprocess conforms to the multiprocessing interface, the examples and documentation found at http://docs.python.org/library/multiprocessing.html also apply to multiprocess if one will import multiprocessing as multiprocess. See https://github.com/uqfoundation/multiprocess/tree/master/py3.12/examples for a set of examples that demonstrate some basic use cases and benchmarking for running Python code in parallel. Please feel free to submit a ticket on github, or ask a question on stackoverflow (@Mike McKerns). If you would like to share how you use multiprocess in your work, please send an email (to mmckerns at uqfoundation dot org).

Citation

If you use multiprocess to do research that leads to publication, we ask that you acknowledge use of multiprocess by citing the following in your publication:

M.M. McKerns, L. Strand, T. Sullivan, A. Fang, M.A.G. Aivazis,
"Building a framework for predictive science", Proceedings of
the 10th Python in Science Conference, 2011;
http://arxiv.org/pdf/1202.1056

Michael McKerns and Michael Aivazis,
"pathos: a framework for heterogeneous computing", 2010- ;
https://uqfoundation.github.io/project/pathos

Please see https://uqfoundation.github.io/project/pathos or http://arxiv.org/pdf/1202.1056 for further information.

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

multiprocess-0.70.16.tar.gz (1.8 MB view details)

Uploaded Source

Built Distributions

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

multiprocess-0.70.16-py312-none-any.whl (146.7 kB view details)

Uploaded Python 3.12

multiprocess-0.70.16-py311-none-any.whl (143.5 kB view details)

Uploaded Python 3.11

multiprocess-0.70.16-py310-none-any.whl (134.8 kB view details)

Uploaded Python 3.10

multiprocess-0.70.16-py39-none-any.whl (133.4 kB view details)

Uploaded Python 3.9

multiprocess-0.70.16-py38-none-any.whl (132.6 kB view details)

Uploaded Python 3.8

multiprocess-0.70.16-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl (135.0 kB view details)

Uploaded PyPymanylinux: glibc 2.28+ x86-64

multiprocess-0.70.16-pp310-pypy310_pp73-macosx_10_13_x86_64.whl (135.0 kB view details)

Uploaded PyPymacOS 10.13+ x86-64

multiprocess-0.70.16-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl (133.5 kB view details)

Uploaded PyPymanylinux: glibc 2.28+ x86-64

multiprocess-0.70.16-pp39-pypy39_pp73-macosx_10_13_x86_64.whl (133.5 kB view details)

Uploaded PyPymacOS 10.13+ x86-64

multiprocess-0.70.16-pp38-pypy38_pp73-manylinux_2_28_x86_64.whl (132.8 kB view details)

Uploaded PyPymanylinux: glibc 2.28+ x86-64

multiprocess-0.70.16-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (132.8 kB view details)

Uploaded PyPymacOS 10.9+ x86-64

File details

Details for the file multiprocess-0.70.16.tar.gz.

File metadata

  • Download URL: multiprocess-0.70.16.tar.gz
  • Upload date:
  • Size: 1.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.18

File hashes

Hashes for multiprocess-0.70.16.tar.gz
Algorithm Hash digest
SHA256 161af703d4652a0e1410be6abccecde4a7ddffd19341be0a7011b94aeb171ac1
MD5 3240912de9afb22fcef7c17513fbcbc8
BLAKE2b-256 b5ae04f39c5d0d0def03247c2893d6f2b83c136bf3320a2154d7b8858f2ba72d

See more details on using hashes here.

File details

Details for the file multiprocess-0.70.16-py312-none-any.whl.

File metadata

File hashes

Hashes for multiprocess-0.70.16-py312-none-any.whl
Algorithm Hash digest
SHA256 fc0544c531920dde3b00c29863377f87e1632601092ea2daca74e4beb40faa2e
MD5 ab08083bf3f2dc577e2a74818c4a7e6e
BLAKE2b-256 0a7da988f258104dcd2ccf1ed40fdc97e26c4ac351eeaf81d76e266c52d84e2f

See more details on using hashes here.

File details

Details for the file multiprocess-0.70.16-py311-none-any.whl.

File metadata

File hashes

Hashes for multiprocess-0.70.16-py311-none-any.whl
Algorithm Hash digest
SHA256 af4cabb0dac72abfb1e794fa7855c325fd2b55a10a44628a3c1ad3311c04127a
MD5 2696ee5fb2a3555dbca3a67e2ff3449f
BLAKE2b-256 5015b56e50e8debaf439f44befec5b2af11db85f6e0f344c3113ae0be0593a91

See more details on using hashes here.

File details

Details for the file multiprocess-0.70.16-py310-none-any.whl.

File metadata

File hashes

Hashes for multiprocess-0.70.16-py310-none-any.whl
Algorithm Hash digest
SHA256 c4a9944c67bd49f823687463660a2d6daae94c289adff97e0f9d696ba6371d02
MD5 16c2e64546a67677ec2d304c817a2e76
BLAKE2b-256 bcf77ec7fddc92e50714ea3745631f79bd9c96424cb2702632521028e57d3a36

See more details on using hashes here.

File details

Details for the file multiprocess-0.70.16-py39-none-any.whl.

File metadata

  • Download URL: multiprocess-0.70.16-py39-none-any.whl
  • Upload date:
  • Size: 133.4 kB
  • Tags: Python 3.9
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.18

File hashes

Hashes for multiprocess-0.70.16-py39-none-any.whl
Algorithm Hash digest
SHA256 a0bafd3ae1b732eac64be2e72038231c1ba97724b60b09400d68f229fcc2fbf3
MD5 679f322042fcf45d6343af219de04091
BLAKE2b-256 dad9f7f9379981e39b8c2511c9e0326d212accacb82f12fbfdc1aa2ce2a7b2b6

See more details on using hashes here.

File details

Details for the file multiprocess-0.70.16-py38-none-any.whl.

File metadata

  • Download URL: multiprocess-0.70.16-py38-none-any.whl
  • Upload date:
  • Size: 132.6 kB
  • Tags: Python 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.18

File hashes

Hashes for multiprocess-0.70.16-py38-none-any.whl
Algorithm Hash digest
SHA256 a71d82033454891091a226dfc319d0cfa8019a4e888ef9ca910372a446de4435
MD5 6a899124a9fa2b94f41d24eb927d9ba2
BLAKE2b-256 ea8938df130f2c799090c978b366cfdf5b96d08de5b29a4a293df7f7429fa50b

See more details on using hashes here.

File details

Details for the file multiprocess-0.70.16-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for multiprocess-0.70.16-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d951bed82c8f73929ac82c61f01a7b5ce8f3e5ef40f5b52553b4f547ce2b08ec
MD5 b6fff33e37d79fe0c774346a152df773
BLAKE2b-256 0fab1e6e8009e380e22254ff539ebe117861e5bdb3bff1fc977920972237c6c7

See more details on using hashes here.

File details

Details for the file multiprocess-0.70.16-pp310-pypy310_pp73-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for multiprocess-0.70.16-pp310-pypy310_pp73-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 476887be10e2f59ff183c006af746cb6f1fd0eadcfd4ef49e605cbe2659920ee
MD5 57e071fae671b506a9ccbf530befbe35
BLAKE2b-256 ef766e712a2623d146d314f17598df5de7224c85c0060ef63fd95cc15a25b3fa

See more details on using hashes here.

File details

Details for the file multiprocess-0.70.16-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for multiprocess-0.70.16-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e7b9d0f307cd9bd50851afaac0dba2cb6c44449efff697df7c7645f7d3f2be3a
MD5 91172aa9e9b90c74441724e6603e2cdc
BLAKE2b-256 8921222066f6bb8d8af287923ae3bd26cf4699a9ce020228ac273caca1de8250

See more details on using hashes here.

File details

Details for the file multiprocess-0.70.16-pp39-pypy39_pp73-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for multiprocess-0.70.16-pp39-pypy39_pp73-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 0dfd078c306e08d46d7a8d06fb120313d87aa43af60d66da43ffff40b44d2f41
MD5 4ecbc2be7525565c11913f385e376e90
BLAKE2b-256 d8948638a89f93c80df329116e6781a060506c7e91e1f4370dc831e9d17a041d

See more details on using hashes here.

File details

Details for the file multiprocess-0.70.16-pp38-pypy38_pp73-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for multiprocess-0.70.16-pp38-pypy38_pp73-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ba8c31889abf4511c7308a8c52bb4a30b9d590e7f58523302ba00237702ca054
MD5 cde09f9fdb1e54d5cee7680d53b8b554
BLAKE2b-256 50076daf536ec054b2cd97d4c57bd38ae3d5a75ce944f4f6560c217194b88886

See more details on using hashes here.

File details

Details for the file multiprocess-0.70.16-pp38-pypy38_pp73-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for multiprocess-0.70.16-pp38-pypy38_pp73-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 37b55f71c07e2d741374998c043b9520b626a8dddc8b3129222ca4f1a06ef67a
MD5 724a55e2b50306df117ab37364535b8d
BLAKE2b-256 4142b77fb443e3f5d9ed1f77e7bfe9424231904e4656c2145135b50b732f8529

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