Module threadpoolexecutor
Modified ThreadPoolExecutor to support threads leaving the thread pool
This includes a global `secede` method that a submitted function can call to
have its thread leave the ThreadPoolExecutor's thread pool. This allows the
thread pool to allocate another thread if necessary and so is useful when a
function realises that it is going to be a long-running job that doesn't want
to take up space. When the function finishes its thread will terminate
gracefully.
This code copies and modifies two functions from the
`concurrent.futures.thread` module, notably `_worker` and
ThreadPoolExecutor._adjust_thread_count` to allow for checking against a global
`threading.local` state. These functions are subject to the following license,
which is included as a comment at the end of this file:
https://docs.python.org/3/license.html
... and are under copyright by the Python Software Foundation
Copyright 2001-2016 Python Software Foundation; All Rights Reserved
source linkClasses
Functions
▶ def rejoin() Have this thread rejoin the ThreadPoolExecutor
This will block until a new slot opens up in the executor. The next thread
to finish a task will leave the pool to allow this one to join.
See also
secede: leave the thread pool
Reexports
▶ def secede(adjust=True) Have this thread secede from the ThreadPoolExecutor
See also
rejoin: rejoin the thread pool
Reexports