Skip to main content

Convenient multiprocessing function for Python

Project description

tools-mp

This Python library provides a convenient one-line multiprocessing option that can be used as follows:

from tools_mp import multiprocess
from tools_mp import process

def any_function( arg_1, arg_2, ..., arg_n ):
    do something
    return result

args = [ 
    {
        'arg_1': arg_1,
        'arg_2': arg_2,
        ...
        'arg_n': arg_n,
        } for arg_1, arg_2, ..., arg_n in arguments
    ]

data = multiprocess(
    function = any_function,
    args = args,
    return_data = True,
    verbose = True,
    workers = 8,
    **kwargs,
    )

data = process(
    function = any_function,
    args = args,
    return_data = True,
    verbose = True,
    workers = 8,
    mp_threshold = 4, # <- if the number of tasks is less than this value,
	# the process function will use single core processing, otherwise it
	# will use multiprocessing. This can speed up the processing of small
	# tasks significantly, as the overhead of multiprocessing is avoided.
    **kwargs,
    )

If verbose=True, the progress of the calculation will be visualized via the tqdm library. If workers=None (default) all available CPU cores will be used for processing. **kwargs will be passed to 'multiprocessing.Pool' as keyword arguments. This is important if you would like to initialize the workers with a specific function or variables for example.

Installation

pip install tools-mp

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

tools_mp-0.2.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

tools_mp-0.2.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file tools_mp-0.2.0.tar.gz.

File metadata

  • Download URL: tools_mp-0.2.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.14

File hashes

Hashes for tools_mp-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9df3602fa8da61d3ac9cfe29a523c275bad90381b7348a8e3668abcbf881b6ad
MD5 e53c5a60ce4ad92770dc816232153414
BLAKE2b-256 70a0e132c1c11587fbbb8d5bc93c77b88eb80da739e7a290debebce2cc5f05a9

See more details on using hashes here.

File details

Details for the file tools_mp-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: tools_mp-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.14

File hashes

Hashes for tools_mp-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c841456ce668358424cd65c0d8051720ff82b435a4d5da908bd91144b07c6d04
MD5 660ee27b239b1a74e9c1f724dccfdd52
BLAKE2b-256 5537b5da2fd9d2d05e20e29fde14843d6970aea2255af78fd9730ced537309f3

See more details on using hashes here.

Supported by

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