Skip to main content

No project description provided

Project description

Parallize

Parallize is a Python package that provides utilities to parallelize both synchronous and asynchronous functions using the concurrent.futures.ProcessPoolExecutor. 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.

Parallize

Parallize is a Python package that provides utilities to parallelize both synchronous and asynchronous functions using the concurrent.futures.ProcessPoolExecutor. 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

  • parallel are the same function but with @parallize decorator or parallize function Here are the benchmark results comparing serial and parallel execution times:
Test Case Serial Execution Time Parallel Execution Time Speedup
test_aparallize 0:00:04.073584 0:00:00.017007 239.5x
test_aparallize_decorator 0:00:04.027461 0:00:00.014918 269.9x
test_parallize 0:00:04.057500 0:00:00.013410 302.6x
test_parallize_decorator 0:00:04.042075 0:00:00.015465 261.4x

Installation

To install Parallize, you can use pip:

pip install parallize

Usage

Parallelizing Synchronous Functions Using Decorator

To parallelize a synchronous function, use the parallize decorator:

from parallize import parallize

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

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

Parallelizing Asynchronous Functions Using Decorator

To parallelize an asynchronous function, use the aparallize decorator:

import asyncio
from parallize import aparallize

@aparallize
async def my_async_function(x, y):
    await asyncio.sleep(1)
    return x + y

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

Another usage without decorator

from parallize import parallize

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

# Call the function as usual
result = parallize(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:

@parallize(max_workers=4)
def my_function(x, y):
    return x + y

@aparallize(max_workers=4)
async def my_async_function(x, y):
    await asyncio.sleep(1)
    return x + y

or

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

async def my_async_function(x, y):
    await asyncio.sleep(1)
    return x + y

parallize(my_function,max_workers=4)(1, 2)
aparallize(my_async_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

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

parallize-0.1.2.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

parallize-0.1.2-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file parallize-0.1.2.tar.gz.

File metadata

  • Download URL: parallize-0.1.2.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-39-generic

File hashes

Hashes for parallize-0.1.2.tar.gz
Algorithm Hash digest
SHA256 8d3aee76ca1ce12404947adb3bc0a55877f2f6b3690e7e411870188dd4b2d5a8
MD5 bbefda65a91ebde96df05c99797541ea
BLAKE2b-256 2f59175fb24e828319d4b80e2c5e7a0940a0a1bd5534ed4d0d4a477e4a02f68d

See more details on using hashes here.

File details

Details for the file parallize-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: parallize-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-39-generic

File hashes

Hashes for parallize-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f165bebcdfed35b6440e20655ccf98906c5b916ca0d384748c77ec9091c136d7
MD5 8cb0ee92835521976efd30309213c002
BLAKE2b-256 c3361081dad1099f9285bdac43e139fcad883a52361c97d922a7502bf3b6519d

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