Skip to main content

Python Thread Manager

Project description

thread-manager-py

Python Thread Manager

✅Build And Test ✅ PyPI version PyPI
CodeFactor

Install

pip install thread-manager-py

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_arguments = [
    ThreadArgument(thread_name=f"[THREAD-{x}]", args=(f"Thread-{x}", x), kwargs={}, )
    for x in range(1, 23)
]
thread_manager = ThreadManager(print_something, thread_arguments)
thread_manager.run()

Simple Usage with decorator

from thread_manager import using_thread

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

# when
for i in range(10):
    # then
    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_arguments = [
    ThreadArgument(thread_name=f"[THREAD-{x}]", args=(f"Thread-{x}",), kwargs={})
    for x in range(1, 23)
]
thread_manager = ThreadManager(func_something, thread_arguments, 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

thread-manager-py-0.0.3.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

thread_manager_py-0.0.3-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file thread-manager-py-0.0.3.tar.gz.

File metadata

  • Download URL: thread-manager-py-0.0.3.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for thread-manager-py-0.0.3.tar.gz
Algorithm Hash digest
SHA256 570549c9437409e7c22f1d8587320362a63b2bdd9c68d4c04e206f28a8fe3a22
MD5 22bfc13f6d73c92774331b007c0a0ba8
BLAKE2b-256 76f01e89477f1bc76d694ed6b85ef5cbfca61dc5ad6b74866beb74537dc26c1d

See more details on using hashes here.

File details

Details for the file thread_manager_py-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for thread_manager_py-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9e7ec23266dd556872bd980d82102cef93bb291805278d012abb3bf6739d48b2
MD5 dc4204afc36e13f81636b35121259017
BLAKE2b-256 7221139a2e85cb9c0c64ef02d1356d95d97f42941c0bbfb2b27024edec8c139f

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