Skip to content

Instantly share code, notes, and snippets.

@loretoparisi
Created August 5, 2021 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loretoparisi/d091574f8eac92977b97b9f3eae32679 to your computer and use it in GitHub Desktop.
Save loretoparisi/d091574f8eac92977b97b9f3eae32679 to your computer and use it in GitHub Desktop.
Python Thread Support with Bounder Thread Pool or Process Executor
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
@loretoparisi
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment