Skip to main content

A library to parallelize the execution of a function in python

Project description

tfrq - an easy way to parallelize processing a function

This library provides an easy way to parallelize the execution of a function in python using the concurrent.futures library. It allows you to run multiple instances of a function simultaneously, making your code run faster and more efficiently. It also provides a simple API for managing the process, allowing you to cancel or wait for the completion of a task. With this library, you can easily take advantage of the power of parallel processing in python.

Here’s an example of how you can use the library to parallelize the execution of the print function:

Example 1:

from tfrq import tfrq
params = ["Hello", "World", "!"]
func = print
tfrq(func=func, params=params, num_cores=3)

Example 2:

def calculate_sum_of_pairs(list_of_pairs):
    results = []
    for pair in list_of_pairs:
        results.append(sum(pair))

    return results


def huge_list_of_data_to_process(data_list):
    params = []

    for data_row in data_list:
        params.append((data_row[0], data_row[1]))

    list_of_results_for_all_pairs = tfrq(calculate_sum_of_pairs, params)

    list_of_results_for_all_pairs = sum(list_of_results_for_all_pairs, [])
    return list_of_results_for_all_pairs

input_list = [[1, 2], [3, 4], [5, 5], [6, 7]]
list_of_results_for_all_pairs = huge_list_of_data_to_process(input_list)
print(list_of_results_for_all_pairs)

This code will call the print function in parallel with the given parameters and use 3 cores, so it will print the given parameters in parallel.

tfrq is an arabic word meaning “To Split”, which is the purpose of this simple method, to split the work of a single function into multiple processes as easy as possible.

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

tfrq-2.0.3.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

tfrq-2.0.3-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file tfrq-2.0.3.tar.gz.

File metadata

  • Download URL: tfrq-2.0.3.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for tfrq-2.0.3.tar.gz
Algorithm Hash digest
SHA256 0b752041a64e308d45554601b7a3d1742bb4cd704355acbbf740c0c379fca5ab
MD5 a85be1f298bdd0d5ee6e84e998ecc6c4
BLAKE2b-256 9f03b75bf3820033ae8ad6dc933f2b398179edbc094ef27796007f90269a80fd

See more details on using hashes here.

File details

Details for the file tfrq-2.0.3-py3-none-any.whl.

File metadata

  • Download URL: tfrq-2.0.3-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for tfrq-2.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 809e0ee4810ae88968bb9c17221635a0820b1368afe2dc79001c9755e0750df7
MD5 77e9359a698d4e7e7749902b8255b71f
BLAKE2b-256 6e7db467f4f0ea5a50c89fced7da47cf3fa94fd10337f03e6ec1e99024d97694

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