concurrent execution in various flavors
Project description
godale
Debauchery tools for concurrent task execution.
Here you find wrappers around some concurrent.futures
, multiprocessing
and billiard
functions
to facilitate switching between parallelization implementations:
concurrent.futures
multithreading: Python 3 standard tool for multithreadingconcurrent.futures
multiprocessing: Python 3 standard tool for multiprocessingmultiprocessing
multiprocessing: Python 3 standard tool for multiprocessingbilliard
multiprocessing: Multiprocessing forcelery
workers.
All four currently implemented wrappers handle parallel execution of the tasks and yield
result (FinishedTask
) objects having result()
and exception()
methods. This enables
catching of exceptions without cancelling remaining tasks.
Usage:
from godale import Executor
# the first function argument will be replaced by items from the "items" argument below
# subsequent arguments and keyword arguments can be passed on using "fargs" and "fkwargs"
def _worker_function(a, b, some_kwarg=None):
return a * b
# multiprocessing the Python 3 way
executor = Executor(executor="concurrent_processes")
for task in executor.as_completed(
func=_worker_function, # function to be executed
iterable=range(100), # items to be parallelized
fargs=(10, ), # other function arguments
fkwargs={"a_kwarg"=True} # function keyword arguments
):
try:
print(task.result())
except ValueError:
print("task failed")
# multithreading the Python 3 way
executor = Executor(executor="concurrent_threads")
for task in executor.as_completed(
func=_worker_function,
iterable=range(100),
fargs=(10, )
):
try:
print(task.result())
except ValueError:
print("task failed")
# multiprocessing within a celery worker
executor = Executor(executor="billiard")
for task in executor.as_completed(
func=_worker_function,
iterable=range(100),
fargs=(10, )
):
try:
print(task.result())
except ValueError:
print("task failed")
# using the multiprocessing standard module
executor = Executor(executor="multiprocessing")
for task in executor.as_completed(
func=_worker_function,
iterable=range(100),
fargs=(10, )
):
try:
print(task.result())
except ValueError:
print("task failed")
# use different start_method than "fork"
# NOTE: with concurrent.futures and Python 3.6 and earlier, "start_method" other than
# "fork" will raise an RuntimeError
for task in executor.as_completed(
func=_worker_function,
iterable=range(100),
fargs=(10, ),
start_method="spawn"
):
try:
print(task.result())
except ValueError:
print("task failed")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
godale-0.3.tar.gz
(4.7 kB
view details)
Built Distribution
godale-0.3-py3-none-any.whl
(6.3 kB
view details)
File details
Details for the file godale-0.3.tar.gz
.
File metadata
- Download URL: godale-0.3.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9bfd9d984348120f9ed8524731eb639b029d9f55001b1f882485fd7ebf33f3a3 |
|
MD5 | 20f9334d8b6c436f4857a053f2fbe479 |
|
BLAKE2b-256 | 176171fadf752d03d001996c73a62af913e46719525be043241e752cb696106a |
File details
Details for the file godale-0.3-py3-none-any.whl
.
File metadata
- Download URL: godale-0.3-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a9d3f2e237e8b3782d455e17cc79ead0cb11c4d522bdf6fb66f8edb210be6bf |
|
MD5 | 76ea13901b736a02aa276e1aae5b6c69 |
|
BLAKE2b-256 | f0fae4d9566b6fb0aaf0f6d605c4498c9377097c48188286a2a2e48b1c703667 |