-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #412 Added thread_pool handler
- Loading branch information
1 parent
3cd8e6d
commit 9579866
Showing
3 changed files
with
83 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import logging | ||
from concurrent.futures import ThreadPoolExecutor | ||
|
||
_pool = None # type: ThreadPoolExecutor|None | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def init_pool(max_workers): | ||
""" | ||
Creates the thread pool with the max workers. | ||
:type max_workers: int | ||
""" | ||
global _pool | ||
_pool = ThreadPoolExecutor(max_workers) | ||
|
||
|
||
def submit(worker, payload_str, access_token): | ||
""" | ||
Submit a new task to the thread pool. | ||
:type worker: function | ||
:type payload_str: str | ||
:type access_token: str | ||
""" | ||
global _pool | ||
if _pool is None: | ||
log.warning('pyrollbar: Thead pool not initialized. Please ensure init_pool() is called prior to submit().') | ||
return | ||
_pool.submit(worker, payload_str, access_token) |
This file contains 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