Skip to main content

Parallize

Parallize is a Python package that provides utilities to parallelize synchronous functions using the concurrent.futures.ProcessPoolExecutor and convert it into async functions to prevent the main thread from blocking. This allows you to execute functions in separate processes, leveraging multiple CPU cores for improved performance.

Features

  • Parallelize Synchronous Functions: Execute synchronous functions in parallel using multiple processes.
  • Parallelize Asynchronous Functions: Execute asynchronous functions in parallel using multiple processes.
  • Customizable Worker Count: Specify the maximum number of worker processes to use, or let the package use the number of available CPU cores by default.

Mini Benchmark

Here are the updated benchmark results comparing serial and parallel execution times using the test_aparallize.py test case:

Test Case Concurrent Execution Time Parallel Execution Time Speedup Tasks Count
test_aparallize_fn 0:00:17.215937 0:00:08.293026 2.08x 2
test_aparallize_10 0:01:25.070893 0:00:13.997451 5.94x 10

Benchmark Details

  • Concurrent Execution Time: The time taken to execute the CPU-bound task concurrently using a ThreadPoolExecutor.
  • Parallel Execution Time: The time taken to execute the same task in parallel using the aparallize decorator.
  • Speedup: The ratio of serial execution time to parallel execution time, indicating the performance improvement achieved by parallelizing the task.

Installation

To install Parallize, you can use pip:

pip install parallize

Usage

from parallize import aparallize

def my_function(x, y):
    return x + y

# Call the function as usual
result = await aparallize(my_function)(1, 2)
print(result)  # This will be executed in a separate process

Customizing the Number of Workers

You can specify the maximum number of worker processes to use by passing the max_workers argument to the decorator:

def my_function(x, y):
    return x + y

result = await aparallize(my_function, max_workers=4)(1, 2)

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Issues

If you encounter any issues or have suggestions for improvements, please open an issue on the GitHub repository.

Acknowledgments

  • Thanks to the Python community for providing powerful tools and libraries for parallel processing.

@vikyw89-20240804

Release files for parallize 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for parallize 0.1.5
File Size Uploaded
parallize-0.1.5.tar.gz 3.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for parallize 0.1.5
File Interpreter ABI Platform
parallize-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 7.3 kB

Release files / parallize-0.1.5.tar.gz

Download URL parallize-0.1.5.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0b0248f1ab3f3e68436c7651fd12d023b6043df8b9b07c0a4a93b0b34ae438e9
BLAKE2b-256 checksum
How to use checksums
e484b5fb54cc0d82bbfbfd7cbe2713cda75bc3ca456299109f8003f2c141710b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-39-generic

Release files / parallize-0.1.5-py3-none-any.whl

Download URL parallize-0.1.5-py3-none-any.whl
Size 4.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
95961c8a2b718847f8fea4d88e777a6f0c6968dd37308c9c5b49a725b4f34b17
BLAKE2b-256 checksum
How to use checksums
48942e6c196067e246af327dc971f91ef18ec88b74eb9ca207552b0986b53605
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-39-generic

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page