Run functions in parallel safely with typesafe parmap!.
Project description
typesafe_parmap
Run functions in parallel safely with typesafe parmap!
- GitHub: https://github.com/thejaminator/typesafe_parmap
- PyPI: https://pypi.org/project/typesafe_parmap/
Features
Easy run different functions in parallel!
import time
from concurrent.futures import ThreadPoolExecutor
from typesafe_parmap.parmap import par_map_2
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-0.1.0.tar.gz
(5.2 kB
view hashes)
Built Distribution
Close
Hashes for typesafe_parmap-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b63a32bf648bdef3eb6910c001c5fa07ace0871d4fe421af3356e206cfedf36 |
|
MD5 | 17abde46facf14359cd18c2208dd1ab4 |
|
BLAKE2b-256 | 72fd97495a4649680197df9959841a9ff16b9247290eff6f98e58850dc5a806c |