728x90
반응형
[Python] 파이썬 Thread and Pool Manager
GitHub 주소
코드
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()
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()
728x90
반응형
'Python > Python' 카테고리의 다른 글
[Python] Linter 비교 (0) | 2022.10.31 |
---|---|
[Python] lru_cache (0) | 2022.09.28 |
[Python] Object class __slots__를 이용한 성능 개선 (0) | 2022.09.28 |
[Python] Concurrency Thread Decorator - 3 (0) | 2022.08.14 |
[Python] Concurrency PDF 파일 생성 - 2 (0) | 2022.08.12 |