--- /dev/null
+Fix endless retry loop in :mod:`profiling.sampling` blocking mode when
+threads cannot be seized due to ``EPERM``. Such threads are now skipped
+instead of causing repeated error messages. Patch by Pablo Galindo.
if (errno == ESRCH) {
return 1; // Thread gone, skip
}
+ if (errno == EPERM) {
+ // Thread may have exited, be in a special state, or already be traced.
+ // Skip rather than fail - this avoids endless retry loops when
+ // threads transiently become inaccessible.
+ return 1;
+ }
if (errno == EINVAL || errno == EIO) {
// Fallback for older kernels
if (ptrace(PTRACE_ATTACH, tid, NULL, NULL) == 0) {
waitpid(tid, &status, __WALL);
return 0;
}
- if (errno == ESRCH) {
- return 1; // Thread gone
+ if (errno == ESRCH || errno == EPERM) {
+ return 1; // Thread gone or inaccessible
}
}
return -1; // Real error