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

tfrq on github!

Stop waiting for your code to finish, start using tfrq - the effortless solution for parallelizing your functions and supercharging your performance!

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:

input_list = [[1, 2], [3, 4], [5, 5], [6, 7]]
list_of_results_for_all_pairs = tfrq(sum, input_list)
print(list_of_results_for_all_pairs)  # [[3], [7], [10], [13]] -- result for each pair ordered.

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

Example 3 - using the config parameter:

input_list = [[1, 2], [3, 4], [5, 5], [6, str(7) + '1']]  # error in final input
list_of_results_for_all_pairs = tfrq(sum, input_list)
print(list_of_results_for_all_pairs)  # [[3], [7], [10], []] -- result for each pair ordered.

input_list = [[1, 2], [3, 4], [5, 5], [6, str(7) + '1']]  # error in final input
list_of_results_for_all_pairs = tfrq(sum, input_list, config={"print_errors": True})
# unsupported operand type(s) for +: 'int' and 'str'
print(list_of_results_for_all_pairs)  # [[3], [7], [10], []] -- result for each pair ordered.

input_list = [[1, 2], [3, 4], [5, 5], [6, str(7) + '1']]  # error in final input
list_of_results_for_all_pairs, errors = tfrq(sum, input_list,
                                             config={"print_errors": True, "return_errors": True})
# unsupported operand type(s) for +: 'int' and 'str'
print(list_of_results_for_all_pairs)  # [[3], [7], [10], []] -- result for each pair ordered.
print(errors)  # [[], [], [], [TypeError("unsupported operand type(s) for +: 'int' and 'str'")]]

Example 4 - “pass_as_single_argument”: False:

params = ["Hello", "World", "!"]
func = print
tfrq(func=func, params=params, num_cores=3, config={"pass_as_single_argument": False})
# H e l l o
# !
# W o r l d ---- notice now it is func(*args) - that is causing the spaces.

params = ["Hello", "World", "!"]
func = print
tfrq(func=func, params=params, num_cores=3, config={"pass_as_single_argument": True})
# Hello
# World
# !

default config:

config = {"pass_as_single_argument": True, "return_errors": False, "print_errors": True}

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.91.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

tfrq-2.0.91-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tfrq-2.0.91.tar.gz
  • Upload date:
  • Size: 7.0 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.91.tar.gz
Algorithm Hash digest
SHA256 a4baaaafba2fb882e152ae3730c9646d18853f2adaa352e07b56934a54f233dd
MD5 b759cb4da954d9a08c7611021c14f9d5
BLAKE2b-256 31bc1e2e31293d0671271bbac78e1ab49bf4bf62d9b72613cbbe0b3be75d73dc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tfrq-2.0.91-py3-none-any.whl
  • Upload date:
  • Size: 7.1 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.91-py3-none-any.whl
Algorithm Hash digest
SHA256 1aae280317d049b0f38009fe4c6b59769d5f6e2ebd941d38c90c91b898264514
MD5 462ee19c8eddb7425f2691710377bcb4
BLAKE2b-256 f37440cb51cdcea63c8df70f60fc8ad4e5bfb192ceeceec023e4aa52b6aeff40

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