Skip to main content

Run functions in parallel safely with typesafe parmap!.

Project description

typesafe_parmap

pypi python Build Status

Run functions in parallel safely with 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)

Uploaded Source

Built Distribution

typesafe_parmap-0.1.0-py3-none-any.whl (4.1 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