Skip to content

Commit f0c1c66

Browse files
MengAiDevMengAiDev
authored andcommitted
Commit message: Improve test cleanup and thread handling in monitoring tests
- Replace manual thread alive checks with `join()` for reliability and efficiency - Disable monitoring events after test to prevent resource leaks - Fix race conditions by ensuring threads terminate before test completion
1 parent 246be21 commit f0c1c66

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

Lib/test/test_free_threading/test_monitoring.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,9 @@ def test_instrumentation(self):
6262

6363
self.after_threads()
6464

65-
while True:
66-
any_alive = False
67-
for t in threads:
68-
if t.is_alive():
69-
any_alive = True
70-
break
71-
72-
if not any_alive:
73-
break
74-
75-
self.during_threads()
65+
# Fix:use join() instead of is_alive()
66+
for t in threads:
67+
t.join()
7668

7769
self.after_test()
7870

@@ -130,6 +122,8 @@ def callback(self, *args):
130122
self.called = True
131123

132124
def after_test(self):
125+
# 修复:确保测试结束后监控被禁用
126+
monitoring.set_events(self.tool_id, 0)
133127
self.assertTrue(self.called)
134128

135129
def during_threads(self):

0 commit comments

Comments
 (0)