Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Commit message: Improve test cleanup and thread handling in monitorin…
…g 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
  • Loading branch information
MengAiDev MengAiDev
MengAiDev authored and MengAiDev committed Jul 21, 2025
commit f0c1c666026a593119291eb8304b3be9e89f8865
16 changes: 5 additions & 11 deletions Lib/test/test_free_threading/test_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,9 @@ def test_instrumentation(self):

self.after_threads()

while True:
any_alive = False
for t in threads:
if t.is_alive():
any_alive = True
break

if not any_alive:
break

self.during_threads()
# Fix:use join() instead of is_alive()
for t in threads:
t.join()

self.after_test()

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

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

def during_threads(self):
Expand Down