Skip to main content

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.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-multithreading-0.0.0.tar.gz (8.0 kB view details)

Uploaded Source

File details

Details for the file python-multithreading-0.0.0.tar.gz.

File metadata

  • Download URL: python-multithreading-0.0.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.0

File hashes

Hashes for python-multithreading-0.0.0.tar.gz
Algorithm Hash digest
SHA256 a56319f5676e8e9cc5e27ccb70b3c11ebff0709a5833b4bcf0fe4ff3418f4729
MD5 1a7d3a46ed6f5e3bbf62a969a75bebd6
BLAKE2b-256 a9c9312fb49867bbd9c0def71853f0cdf2058614b4b58397ae5aca548a75f39c

See more details on using hashes here.

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