Skip to main content

a drop-in and easy-use enhancement for multiprcocessing

Project description

multiprocplus

multiprocessing plus, a drop-in and easy-use enhancement for multiprcocessing

  • easy to replace "for loop".
  • assign task group with given an estimated cost.

install

# install method 1: from source code
git clone https://github.com/yinglang/multiprocplus
cd multiprocplus
python setup.py install
# install method 2: from pip (TODO)

Usage

from multiprocplus import multiprocess_for, MultiprocessRunner

# func passed to new process must be global function or 
# member function of global class, and not lambda function
def func(a, b):
    return a * b

if __name__ == "__main__":
    N = 100
    A, B = list(range(N)), list(range(N))
    # run in single process
    C = [func(a, b) for a, b in zip(A, B)]
    print(sum(C))
    # => run in multiprocess
    # only allow to be called under 'if __name__ == "__main__"' of entry script
    C = multiprocess_for(func, [(a, b) for a, b in zip(A, B)], num_process=3)
    print(sum(C))

For more usage examples, see doc/usage.md

Notice:

  1. The definition of function passed to new process must be out of 'if name == "main"' (global function or member function of global class), and can not be lambda function;
  2. Code/Function that you do not want to run in new process must be written/called under 'if name == "main"' of entry script, or it will run/called in new process.
  3. Following last note, multiprocess_run must be called in a function called under 'if name == "main"' of entry script. Otherwise, new processes will be generated recursively

For error usage examples, to see doc/normal_issue.md or test/error_usage

Basic && Implementation

Manager & Pool in multiprocessing

If you have known the usage of module multiprocessing in python, you can skip this section. see CSDN

Implementation

If you just want to use multiprocplus in you project and do not interest the implementation, you can skip this section.

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

multiprocplus-0.1.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

multiprocplus-0.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file multiprocplus-0.1.tar.gz.

File metadata

  • Download URL: multiprocplus-0.1.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.5

File hashes

Hashes for multiprocplus-0.1.tar.gz
Algorithm Hash digest
SHA256 e67df4321f6f8e5e388405d382a00e53fdc575126eafcefee170346841e7f682
MD5 74ea832d644981f25dcbde0bb4764034
BLAKE2b-256 aadf1e51a1c72db1be989763a401cedcc7dda341a19c3a9f3705919ba961d32e

See more details on using hashes here.

File details

Details for the file multiprocplus-0.1-py3-none-any.whl.

File metadata

  • Download URL: multiprocplus-0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.5

File hashes

Hashes for multiprocplus-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 01b5e5518ce5fc4d930cff2e39dddb7e277ec31f4a4ccb3ec347791a987cd043
MD5 558eecd402b42d42b65b1e406bbce651
BLAKE2b-256 c82229004ccab6a3f0a0534ac2461bb3f43adc7f679d374b2c334841e3e7ea51

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