A python module for creating multithreading processes easily, in a more Pythonic way.
Project description
multithreading
A python module for creating multithreading processes easily, in a more Pythonic way.
Installation
pip install python-multithreading
example
import time
from multithreading import Caller, multi_threaded_call
def slow_function(number: int, delay: float) -> dict[str, int | float]:
for i in range(number):
time.sleep(delay)
return dict(number=number, delay=delay)
CALLS = 50
DELAY = 0.01
NUMBER = 100
callers = [
Caller(
target=slow_function,
kwargs=dict(delay=DELAY, number=NUMBER)
) for _ in range(CALLS)
]
s = time.time()
multi_threaded_call(callers)
e = time.time()
print("multi-threading: ", e - s)
s = e
all(slow_function(*caller.args, **caller.kwargs) for caller in callers)
e = time.time()
print("single-threading: ", e - s)
output
multi-threading: 1.0473840236663818
single-threading: 52.53497314453125
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for python-multithreading-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55fbb7f495fd66ec71131253819dc7d0537f07ea7ae207b23af5bfa40a49626a |
|
MD5 | fd8083142ac069d3190f527e1bd6464b |
|
BLAKE2b-256 | ec7ec0e1aba363ed478448bb6d101021af9bc24ccda0da13a269a3cb628548d4 |