Run functions in parallel safely with typesafe parmap!.
Project description
typesafe_parmap
pip install pip install typesafe-parmap
Run functions in parallel safely with typesafe parmap!
Features
Easy run different functions in parallel!
from typesafe_parmap import par_map_2
import time
from concurrent.futures import ThreadPoolExecutor
tp = ThreadPoolExecutor(5)
def long_running_int(param: int) -> int:
time.sleep(5) # long IO task here
return 123
def long_running_str(param: str) -> str:
time.sleep(5) # long IO task here
return "hello world"
int_result, str_result = par_map_2(
lambda: long_running_int(5),
lambda: long_running_str("test"),
executor=tp)
assert int_result == 123, str_result == "hello world" # should finish in 5 seconds
Function return types are inferred correctly by mypy / pycharm!
reveal_type(int_result) # mypy infers int
reveal_type(str_result) # mypy infers str
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
typesafe_parmap-1.0.2.tar.gz
(5.2 kB
view hashes)
Built Distribution
Close
Hashes for typesafe_parmap-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9427bad5d7461a3d0e5beecd368ee6b25345d41fec23376acfd0607589a1ba85 |
|
MD5 | 54f7a645bc44f5fb65fa22d8dd5ef091 |
|
BLAKE2b-256 | ddcf2e716a0ee38e378494377e7ee5a502d1f8ff23cca2a2728512ccdcbed62c |