ThreadPoolExecutor - callback guaranteed to run in same thread as the submitted function?
dieter at handshake.de
Thu Sep 25 08:14:26 CEST 2014
Praveen Gollakota <pgollakota at gmail.com> writes:
> In the ThreadPoolExecutor (TPE), is the callback always guaranteed to run in the same thread as the submitted function?
To answer question of this type (yourself), you may look
at the relevant source code.
I am quite sure that the "submitted function" will be executed
in one of the threads from the thread pool.
I have not looked at the "ThreadPoolExecutor" code. The easiest thing
would be to run the callback in the same thread as the submitted function.
However, it could facilitate use of the "ThreadPoolExecutor"
(less locking) when the synchronisation were done inside
the "ThreadPoolExecutor" and the callbacks were executed in a single
thread (likely the one which has set up the "ThreadPoolExecutor").
A look at the source should tell the details.
More information about the Python-list