Skip to main content

thread-manager-py

Python Thread Manager

✅Build And Test ✅ PyPI version PyPI
CodeFactor PyPI

Install

pip install thread-manager-py

Pool Manager Usage

You can find examples in test/test_pool_manager.py.

Simple Usage

import os
from pool_manager import PoolManager

def calculate(x):
    print(f"[{os.getpid()}]  func: {x}\t\t", r := x ** 5 ** 2, flush=True)
    return r

manager = PoolManager()
manager.add_task(calculate, [i for i in range(2, 22)])
manager.run_map()

manager.add_task(calculate, [i for i in range(2, 22)])
manager.add_task(calculate, [i for i in range(2, 22)])
manager.run_map()

task_result = manager.get_task_result()
with PoolManager() as manager:
    manager.add_task(calculate, [i for i in range(2, 22)])
    manager.add_task(calculate, [i for i in range(2, 22)])
    manager.add_task(calculate, [i for i in range(2, 22)])
    manager.run_map()

Thread Manager Usage

You can find examples in test/test_thread_manager.py.

Simple Usage

import time
from thread_manager import ThreadManager, ThreadArgument

def print_something(name: str, number: int):
    print(name, number)
    time.sleep(1)

    
thread_manager = ThreadManager(print_something, [
    ThreadArgument(thread_name=f"Thread:{x}", args=(x, x) )
    for x in range(1, 23)
])
thread_manager.run()

Get Thread Error

errors = thread_manager.get_errors()
has_error = thread_manager.has_error()
error_count = thread_manager.get_error_count()

for e in errors:
    print(e)

Simple Usage with decorator

from thread_manager import using_thread

@using_thread
def print_something(number, **kwargs):
    print(number, kwargs)

for i in range(10):
    print_something(i, name=f"thread-{i}")

Simple Usage with Exception Hook

from thread_manager import ThreadManager, ThreadArgument

errors = []

def func_something(*args):
    raise Exception("test error")

def func_exception_hook(*args):
    errors.append(args)

thread_manager = ThreadManager(func_something, [
    ThreadArgument(thread_name=f"Thread:{x}", args=(x, x), kwargs={}, )
    for x in range(1, 23)
], except_hook=func_exception_hook)
thread_manager.run()

Metadata

Release files for thread-manager-py 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for thread-manager-py 0.3.0
File Size Uploaded
thread-manager-py-0.3.0.tar.gz 8.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for thread-manager-py 0.3.0
File Interpreter ABI Platform
thread_manager_py-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.3 kB

Release files / thread-manager-py-0.3.0.tar.gz

Download URL thread-manager-py-0.3.0.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f1d06f93ebbbfedcca27a67841371d9a1e0107a717973bef50e828c9004e68f1
BLAKE2b-256 checksum
How to use checksums
69ab83c9913bea2dcdc7e31489437221b29fcfc8ed08afe9d5fa106e00e8e63a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Release files / thread_manager_py-0.3.0-py3-none-any.whl

Download URL thread_manager_py-0.3.0-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
993d2f57aecfaa583fb5956a4326def9d4d7e7ed009efd955003959849eb7b25
BLAKE2b-256 checksum
How to use checksums
902f33477c85da848211cc89221cef05b6299f56b8c8794d02b15caa6f5366b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page