bpo-35493: Use Process.sentinel instead of sleeping for polling worker status in multiprocessing.Pool by pablogsal · Pull Request #11488 · python/cpython

@vstinner @pitrou I had to rebase since the changes in https://bugs.python.org/issue35378 make the handle_workers independent on the pool itself, so we cannot rely on the thread keeping the pool alive or to use self in the waiting_for_updates function. Some new changes are needed, for example, gathering the sentinels needs to be done in the constructor to avoid references to self:

https://github.com/python/cpython/pull/11488/files#diff-2d95253d6de7bbeebbeb131c5f3aecd9R213

the if blocks are needed to make the ThreadPool constructor not crash.

Also, the minimal timeout needs to still exist because now that the thread does not keep the pool alive, it needs a wait to exit from _wait_for_updates if the pool does not unblock the sentinels because is dead

To avoid hanging if the pool dies too quickly, I have changed the del to push a notification to unblock the worker thread:

https://github.com/python/cpython/pull/11488/files#diff-2d95253d6de7bbeebbeb131c5f3aecd9R269