Skip to main content

a light multiprocessing/multithreading work dispatcher for python.

Project description

wworks

a light multiprocessing/multithreading work dispatcher for python.

Generic badge GitLab tags License: MIT

wworks (Wrapped Works) is a work manager that uses both ProcessPoolExecutor and ThreadPoolExecutor to dispatch work by workload over processes and/or threads.

Installation

Check your python version (must be >= 3.7)

> python --version
Python 3.8.12

Install wworks package

> pip install wworks

Usage examples

WorkManager.work(work_name, work_to_do, work_data)

Use WorkManager.work to make multithreading for given function.

from wworks.swworks import WorkManager

def multiply(x, y):
    return x*y

# Build 10 tuples from (0, 0) to (9, 9)
work_data = [(x, x) for x in range(10)]
results = WorkManager().work("multiply", multiply, work_data)
for (task_name, task_data, task_result) in results:
    print(f"{task_name} : multiply{task_data} => {task_result}")
Task #0 : multiply(0, 0) => 0
Task #1 : multiply(1, 1) => 1
Task #2 : multiply(2, 2) => 4
Task #3 : multiply(3, 3) => 9
Task #4 : multiply(4, 4) => 16
Task #5 : multiply(5, 5) => 25
Task #6 : multiply(6, 6) => 36
Task #7 : multiply(7, 7) => 49
Task #8 : multiply(8, 8) => 64
Task #9 : multiply(9, 9) => 81

In this case, WorkManager create 10 tasks (threads) to process.

WorkManager.chunks(lst, n)

Use WorkManager.chunks to yield n-sized chunks from lst.

from wworks.swworks import WorkManager

# Build 10 tuples from (0, 0) to (9, 9)
work_data = [(x, x) for x in range(10)]
results = WorkManager().chunks(work_data, 4)
for i, chunk in enumerate(results):
    print(f"Chunk #{i}")
    print(chunk)
Chunk #0
[(0, 0), (1, 1), (2, 2), (3, 3)]
Chunk #1
[(4, 4), (5, 5), (6, 6), (7, 7)]
Chunk #2
[(8, 8), (9, 9)]

In this case, WorkManager yield 4-chunks from all provided tuples.

WorkManager.dispatch(work_to_do, work_data, workload=4)

Use WorkManager.dispatch to make chunked-by-process, multithreading for given function.

from wworks.swworks import WorkManager

def multiply(x, y):
    return x*y

# Build 10 tuples from (0, 0) to (9, 9)
work_data = [(x, x) for x in range(10)]
results = WorkManager().dispatch(multiply, work_data)
for (worker_name, worker_result) in results:
    print(worker_name)
    for (task_name, task_data, task_result) in worker_result:
        print(f" - {task_name} : multiply{task_data} => {task_result}")
Worker #0
 - Task #0 : multiply(0, 0) => 0
 - Task #1 : multiply(1, 1) => 1
 - Task #2 : multiply(2, 2) => 4
 - Task #3 : multiply(3, 3) => 9
Worker #1
 - Task #0 : multiply(4, 4) => 16
 - Task #1 : multiply(5, 5) => 25
 - Task #2 : multiply(6, 6) => 36
 - Task #3 : multiply(7, 7) => 49
Worker #2
 - Task #0 : multiply(8, 8) => 64
 - Task #1 : multiply(9, 9) => 81

In this case, WorkManager create 3 workers (processes) and give each of them chunked work data respectivelly 4, 4 and 2 tasks to process.

Release History

  • 0.1.0
    • First version of wworks package

Meta

Mehdi LAKBIR

Twitter URL

Distributed under the MIT license. See LICENSE for more information.

https://https://github.com/LMKA/wworks

Contributing

  1. Fork it (https://github.com/LMKA/wworks/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

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

wworks-0.1.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

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

wworks-0.1.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file wworks-0.1.0.tar.gz.

File metadata

  • Download URL: wworks-0.1.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for wworks-0.1.0.tar.gz
Algorithm Hash digest
SHA256 58a613e47db4bd9098da734fecece33f3a4cccf1b27a3ec8b0964ccc1e7b4daa
MD5 656b34437ab122ca3a48594ed23f4ced
BLAKE2b-256 9e13cbd8858c81d548ffee2087fae892f3faf8d43cfcb4b8f7e96a3fa00efddb

See more details on using hashes here.

File details

Details for the file wworks-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: wworks-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for wworks-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8bb1225033bd831eaa281a73c914191f93db5a80d3f02197ea2ccede83bdfafa
MD5 1e360432a8fcadd495b616e79be7b6ae
BLAKE2b-256 0f6f01a1acc49db6572ecdff5c67f442874758cf0567c8748adb2789041a8508

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