threading_manager
Designed to working with spawned threads.
Features
- use different managers for different funcs/methods if needed
- use just one decorator to spawn threads from func/methods
- keep all spawned threads in list by ThreadItem objects
- ThreadItem keeps result/exx/is_alive attributes!
- use wait_all()
License
See the LICENSE file for license rights and limitations (MIT).
Release history
See the HISTORY.md file for release history.
Installation
pip install -U threading-manager
Import
from threading_manager import *
GUIDE
See tests and source for other examples.
from threading_manager import *
count = 5
time_start = time.time()
class ThreadManager1(ThreadsManager):
pass
class Cls:
@ThreadManager1().decorator__to_thread
def func1(self, num):
time.sleep(1)
return num * 1000
for i in range(count):
assert Cls().func1(i) is None
assert ThreadManager1().COUNTER == count
ThreadManager1().wait_all()
assert {item.result for item in ThreadManager1().THREAD_ITEMS} == {num * 1000 for num in range(count)}
ThreadManager1().thread_items__clear()
for i in range(count):
assert Cls().func1(i) is None