New GitHub issue #107616 from mariokostelac:<br>
<hr>
<pre>
# Bug report
## Checklist
- [x] I am confident this is a bug in CPython, not a bug in a third-party project
- [x] I have searched the CPython issue tracker, and am confident this bug has not been reported before
## A clear and concise description of the bug
Multiprocessing.dummy.Pool is not joining running threads as part of the shutdown procedure.
>From what I understand, it's supposed to happen in https://github.com/python/cpython/blob/0bd784b355edf0d1911a7830db5d41c84171e367/Lib/multiprocessing/pool.py#L726-L732, but because https://github.com/python/cpython/blob/0bd784b355edf0d1911a7830db5d41c84171e367/Lib/multiprocessing/dummy/__init__.py#L34-L59 doesn't have a `terminate` attr, it doesn't join threads but just proceeds.
Should https://github.com/python/cpython/blob/0bd784b355edf0d1911a7830db5d41c84171e367/Lib/multiprocessing/pool.py#L726 just check for existence of `join` attribute instead?
## Repro
```py
import time
from multiprocessing.dummy import Pool as ThreadPool
def sleep_and_print(i):
print("Worker start", i)
time.sleep(i)
print("Worker end", i)
if __name__ == "__main__":
print("** multiprocessing.dummy.Pool test")
print("before thread pool")
with ThreadPool(2) as pool:
try:
results = [pool.apply_async(sleep_and_print, (i,)) for i in [1, 2]]
results[0].get()
raise Exception("test")
except Exception as e:
print("Exception caught", e)
print("after thread pool is destroyed")
# Give enough time for result[1] to finish
time.sleep(2)
```
Output:
```
** multiprocessing.dummy.Pool test
before thread pool
Worker start 1
Worker start 2
Worker end 1
Exception caught test
after thread pool is destroyed
Worker end 2
```
We can see that "worker end 2" happened after the thread pool was supposed to be destroyed, and threads properly joined.
# Your environment
- CPython versions tested on: `Python 3.11.4 (main, Jun 20 2023, 17:23:00) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin`
- Operating system and architecture: `Darwin Marios-MacBook-Pro.local 22.6.0 Darwin Kernel Version 22.6.0: Wed Jul 5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000 arm64`
</pre>
<hr>
<a href="https://github.com/python/cpython/issues/107616">View on GitHub</a>
<p>Labels: type-bug</p>
<p>Assignee: </p>