Skip to main content

better multiprocessing and multithreading in python

Project description

About Multiprocess

multiprocess is a fork of multiprocessing, and is developed as part of pathos: https://github.com/uqfoundation/pathos

multiprocessing is a package for the Python language which supports the spawning of processes using the API of the standard library’s threading module. multiprocessing has been distributed in the standard library since python 2.6.

Features:

  • Objects can be transferred between processes using pipes or multi-producer/multi-consumer queues.

  • Objects can be shared between processes using a server process or (for simple data) shared memory.

  • Equivalents of all the synchronization primitives in threading are available.

  • A Pool class makes it easy to submit tasks to a pool of worker processes.

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.

NOTE: A C compiler is required to build the included extension module. For python 3.3 and above, a C compiler is suggested, but not required.

Major Changes

  • enhanced serialization, using dill

Current Release

This documentation is for version multiprocess-0.70.12.1 (a fork of multiprocessing-0.70a1).

The latest released version of multiprocess is available from:

https://pypi.org/project/multiprocess

Multiprocessing is distributed under a BSD license.

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 is packaged to install from source, so you must download the tarball, unzip, and run the installer:

[download]
$ tar -xvzf multiprocess-0.70.12.1.tgz
$ cd multiprocess-0.70.12.1
$ python setup.py build
$ python setup.py install

You will be warned of any missing dependencies and/or settings after you run the “build” step above.

Alternately, multiprocess can be installed with pip or easy_install:

$ pip install multiprocess

NOTE: A C compiler is required to build the included extension module from source. For python 3.3 and above, a C compiler is suggested, but not required. Binary installs do not require a C compiler.

Requirements

multiprocess requires:

- ``python``, **version == 2.7** or **version >= 3.6**, or ``pypy``
- ``dill``, **version >= 0.3.4**

Optional requirements:

- ``setuptools``, **version >= 0.6**

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. See multiprocess.examples for a set of example scripts. You can also run the test suite with python -m multiprocess.tests. 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 post 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.12.1.zip (3.3 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.12.1-cp27-cp27m-win_amd64.whl (93.3 kB view details)

Uploaded CPython 2.7mWindows x86-64

multiprocess-0.70.12.1-cp27-cp27m-win32.whl (92.3 kB view details)

Uploaded CPython 2.7mWindows x86

File details

Details for the file multiprocess-0.70.12.1.zip.

File metadata

  • Download URL: multiprocess-0.70.12.1.zip
  • Upload date:
  • Size: 3.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.18.1 setuptools/56.1.0 requests-toolbelt/0.8.0 tqdm/4.60.0 CPython/3.6.13

File hashes

Hashes for multiprocess-0.70.12.1.zip
Algorithm Hash digest
SHA256 d73afab98823e06423f68271cce77743fd82ce587090bf5a6ce408396d9a68f3
MD5 c32e3a3ae269afbd5fc442916d01e13d
BLAKE2b-256 26197034777e8ffe6892a27d232466ac81400e7dfb98ba1d3438a15344d2f565

See more details on using hashes here.

File details

Details for the file multiprocess-0.70.12.1-cp27-cp27m-win_amd64.whl.

File metadata

  • Download URL: multiprocess-0.70.12.1-cp27-cp27m-win_amd64.whl
  • Upload date:
  • Size: 93.3 kB
  • Tags: CPython 2.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.18.1 setuptools/56.1.0 requests-toolbelt/0.8.0 tqdm/4.60.0 CPython/3.6.13

File hashes

Hashes for multiprocess-0.70.12.1-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 da2dd17c888b49c82e875a33d2c83c87b56a202a0d736c73b1a059fa311589e0
MD5 2089926559f0ec338c05a631c87440ce
BLAKE2b-256 a86531a542d7f3271a86b69599aae812bb37d40482a9b7d40d608d11b3858a62

See more details on using hashes here.

File details

Details for the file multiprocess-0.70.12.1-cp27-cp27m-win32.whl.

File metadata

  • Download URL: multiprocess-0.70.12.1-cp27-cp27m-win32.whl
  • Upload date:
  • Size: 92.3 kB
  • Tags: CPython 2.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.18.1 setuptools/56.1.0 requests-toolbelt/0.8.0 tqdm/4.60.0 CPython/3.6.13

File hashes

Hashes for multiprocess-0.70.12.1-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 fa41681968d53c219239e1c34d63ac7afc78bb38a934c9bbf8b65340ca8084d3
MD5 9e0cae0ab3f6c916c50f993dd71450c4
BLAKE2b-256 1383896bcd2b08d4143228fe511ed34824e53ab3a86f7a3bb4a231eab4c1a9aa

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