Skip to content

Commit 28081fe

Browse files
authored
gh-159130: _remote_debugging: Do not return another thread when the selected thread is filtered out (#159132)
1 parent f05dde9 commit 28081fe

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎Lib/test/test_external_inspection.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3848,6 +3848,30 @@ def gen():
38483848
skip_non_matching_threads=True,
38493849
)
38503850

3851+
@requires_gil_enabled("Free threaded builds don't have an 'active thread'")
3852+
def test_filtered_active_thread_is_not_replaced(self):
3853+
samples = []
3854+
3855+
def sample():
3856+
for kwargs in ({"all_threads": True}, {"only_active_thread": True}):
3857+
unwinder = RemoteUnwinder(
3858+
os.getpid(), mode=PROFILING_MODE_EXCEPTION, **kwargs
3859+
)
3860+
samples.append(
3861+
self._get_thread_statuses(unwinder.get_stack_trace())
3862+
)
3863+
3864+
thread = threading.Thread(target=sample)
3865+
try:
3866+
raise ValueError
3867+
except ValueError:
3868+
thread.start()
3869+
thread.join()
3870+
3871+
all_threads, active_thread = samples
3872+
self.assertEqual(list(all_threads), [threading.get_native_id()])
3873+
self.assertEqual(active_thread, {})
3874+
38513875

38523876
@requires_remote_subprocess_debugging()
38533877
class TestFrameCaching(RemoteInspectionTestBase):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix :mod:`!_remote_debugging` returning a different thread when the selected
2+
thread does not match the profiling mode with ``only_active_thread=True``.

‎Modules/_remote_debugging/module.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,9 @@ _remote_debugging_RemoteUnwinder_get_stack_trace_impl(RemoteUnwinderObject *self
796796
goto exit;
797797
}
798798
// Thread was skipped due to mode filtering, continue to next thread
799+
if (self->tstate_addr || self->only_active_thread) {
800+
break;
801+
}
799802
continue;
800803
}
801804
// This was an actual error

0 commit comments

Comments
 (0)