Skip to main content

Python wrappers for easy multiprocessing and threading

Project description

parallel-execute

python wrappers for easy multiprocessing and threading

Usage:

# To use threading
from parallel_execute.thread import ThreadLoom
# To use multiprocessing
from parallel_execute.process import ProcessLoom

#####1. Create Loom object This takes a number of tasks and executes them using a pool of threads/process.

# Provide max_runner_cap
loom = ThreadLoom(max_runner_cap=20)

#####2. Add tasks in loom Use add_func(func, arg1, arg2, ..., kwarg1=foo, kwarg2=bar, ...) or add_function(func, arglist, kwargdict) to add a single function to be done.

loom.add_function(f1, args1, kw1)
loom.add_function(f2, args2, kw2)
loom.add_function(f3, args3, kw3)

#####3. Add multiple tasks together Use add_work([f1, a1, kw1), (f2, a2, kw2), ...]) to add a list of functions and kwargs.

work = [(f1, args1, kwargs1), (f2, args2, kwargs2), (f3, args3, kwargs3)]
loom.add_work(work)

#####4. Execute all tasks After adding tasks, calling execute will return a dictionary of results corresponding to the keys or the order in which the tasks were added.

output = loom.execute()

This does not support timeouts, so all runners must complete. To handle timeouts, each runner would have to keep track of its own timeout time, and throw an exception to signal an error to the Loom

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

parallel-execute-0.0.1.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

parallel_execute-0.0.1-py3-none-any.whl (8.1 kB view hashes)

Uploaded Python 3

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