Python Thread Manager
Project description
thread-manager-py
Python Thread Manager
Install
pip install thread-manager-py
Pool Manager Usage
You can find examples in tests/test_package.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()
Thread Manager Usage
You can find examples in tests/test_package.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), kwargs={}, ) 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()
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
Built Distribution
File details
Details for the file thread-manager-py-0.2.0.tar.gz
.
File metadata
- Download URL: thread-manager-py-0.2.0.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8082a940ec192bd02b5a404b7e2d9f834feb00a5b42cbf471fb9beb5058f6b04 |
|
MD5 | aa4d292e4b7ea9c9ad4cb08a06343700 |
|
BLAKE2b-256 | 692508e74e4895fce47d2cca6341217783bcaa4f51a40b4212bffd106ad9a577 |
File details
Details for the file thread_manager_py-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: thread_manager_py-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c84854f541ab2246d8ce0767559daacc825a5cb93d060b8478614bd8b7d54aa |
|
MD5 | 2ca7165f22a03391ab166cd15439698d |
|
BLAKE2b-256 | f512415ba5d22ca0abd3bd7b5c15e380b2ad07913471c85084d903113cc9e814 |