Skip to content

Commit 4384239

Browse files
committed
follow copliot comment and reduce concurrent threads count
1 parent 266ced2 commit 4384239

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

Lib/test/test_free_threading/test_threading.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,28 @@ def shutdown_worker():
3838
pass
3939

4040
def startup_worker():
41-
handles = []
4241
for _ in range(ITERATIONS):
4342
handle = _thread.start_joinable_thread(
4443
lambda: None,
4544
daemon=False,
4645
)
47-
handles.append(handle)
48-
for handle in handles:
4946
handle.join()
5047

48+
# The workers must be daemon threads so _thread._shutdown() ignores them
49+
# and only scans the non-daemon handles created by startup_worker().
5150
workers = [
52-
threading.Thread(target=shutdown_worker, daemon=True),
53-
*[threading.Thread(
54-
target=startup_worker, daemon=True) for _ in range(STARTUP_THREADS)],
51+
threading.Thread(target=shutdown_worker, daemon=True),
52+
*[
53+
threading.Thread(target=startup_worker, daemon=True)
54+
for _ in range(STARTUP_THREADS)
55+
],
5556
]
5657

57-
with threading_helper.start_threads(workers):
58-
pass
58+
with threading_helper.catch_threading_exception() as cm:
59+
with threading_helper.start_threads(workers):
60+
pass
61+
if cm.exc_value is not None:
62+
raise cm.exc_value
5963

6064
if __name__ == "__main__":
6165
unittest.main()

0 commit comments

Comments
 (0)