Skip to main content

Execute Python functions with multithreading.

Project description

Overview

Execute Python functions with multithreading.

Usage

Installation:

pip3 install multithreader
# or
python3 -m pip install multithreader

Example:

def test_function(
    iterator,
    items
) -> int:
    """Sum two numbers."""
    print(iterator)
    sleep(1)
    return items['a'] + items['b']

# Import multithreader.
from multithreader import threads

# Define arguments.
items = {
    'a': 1,
    'b': 2
}

# Define iterators.
iterators = [1, 2, 3, 4, 5]

# Execute function with multithreading.
results = threads(
    test_function,
    iterators,
    items,
    thread_num=int(sys.argv[1])
)

# Print results.
print(results)

Full Example

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

multithreader-1.0.4.tar.gz (2.0 kB view hashes)

Uploaded Source

Built Distribution

multithreader-1.0.4-py3-none-any.whl (2.8 kB view hashes)

Uploaded Python 3

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