New GitHub issue #95166 from graingert:<br>
<hr>
<pre>
<!--
If you're new to Python and you're not sure whether what you're experiencing is a bug, the CPython issue tracker is not
the right place to seek help. Consider the following options instead:
- reading the Python tutorial: https://docs.python.org/3/tutorial/
- posting in the "Users" category on discuss.python.org: https://discuss.python.org/c/users/7
- emailing the Python-list mailing list: https://mail.python.org/mailman/listinfo/python-list
- searching our issue tracker (https://github.com/python/cpython/issues) to see if
your problem has already been reported
-->
# Bug report
```python
import contextlib
import functools
import concurrent.futures
import threading
import sys
def fn(num, stop_event):
if num == 1:
stop_event.wait()
return "done 1"
if num == 2:
return "done 2"
def main():
stop_event = threading.Event()
log = []
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as pool:
def print_n_wait(ident):
log.append(f"{ident=} started")
try:
stop_event.wait()
finally:
log.append(f"{ident=} stopped")
fut = pool.submit(print_n_wait, ident="first")
try:
with contextlib.closing(pool.map(print_n_wait, ["second", "third"], timeout=1)) as gen:
try:
next(gen)
except concurrent.futures.TimeoutError:
print("timed out")
else:
raise RuntimeError("timeout expected")
finally:
stop_event.set()
assert log == ["ident='first' started", "ident='first' stopped"], f"{log=} is wrong"
if __name__ == "__main__":
sys.exit(main())
```
result in:
```
timed out
Traceback (most recent call last):
File "/home/graingert/projects/executor_map.py", line 45, in <module>
sys.exit(main())
File "/home/graingert/projects/executor_map.py", line 42, in main
assert log == ["ident='first' started", "ident='first' stopped"], f"{log=} is wrong"
AssertionError: log=["ident='first' started", "ident='first' stopped", "ident='second' started", "ident='second' stopped"] is wrong
```
# Your environment
<!-- Include as many relevant details as possible about the environment you experienced the bug in -->
- CPython versions tested on:
- Operating system and architecture:
<!--
You can freely edit this text. Remove any lines you believe are unnecessary.
-->
</pre>
<hr>
<a href="https://github.com/python/cpython/issues/95166">View on GitHub</a>
<p>Labels: type-bug</p>
<p>Assignee: </p>