Created
August 5, 2021 16:56
-
-
Save loretoparisi/d091574f8eac92977b97b9f3eae32679 to your computer and use it in GitHub Desktop.
Python Thread Support with Bounder Thread Pool or Process Executor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import wraps | |
from .bounded_pool_executor import BoundedThreadPoolExecutor | |
from .bounded_pool_executor import BoundedProcessPoolExecutor | |
_DEFAULT_POOL = BoundedThreadPoolExecutor(max_workers=5) | |
_PROCESS_POOL = BoundedProcessPoolExecutor(max_workers=5) | |
def threadpool(f, executor=None): | |
@wraps(f) | |
def wrap(*args, **kwargs): | |
return (executor or _DEFAULT_POOL).submit(f, *args, **kwargs) | |
return wrap | |
def processpool(f, executor=None): | |
@wraps(f) | |
def wrap(*args, **kwargs): | |
return (executor or _PROCESS_POOL).submit(f, *args, **kwargs) | |
return wrap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bounded_pool_executor.py