Skip to content

Commit f734745

Browse files
committed
Add _PY_FAIL_IF_INTERRUPTED flag
Don't call signal handlers if interrupted, only return PY_LOCK_INTR.
1 parent b754673 commit f734745

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

Include/internal/pycore_lock.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ typedef enum _PyLockFlags {
4848

4949
// Handle signals if interrupted while waiting on the lock.
5050
_PY_LOCK_HANDLE_SIGNALS = 2,
51+
52+
// Fail if interrupted by a signal while waiting on the lock.
53+
_PY_FAIL_IF_INTERRUPTED = 4,
5154
} _PyLockFlags;
5255

5356
// Lock a mutex with an optional timeout and additional options. See

Python/lock.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ _PyMutex_LockTimed(PyMutex *m, PyTime_t timeout, _PyLockFlags flags)
119119
return PY_LOCK_INTR;
120120
}
121121
}
122+
else if (ret == Py_PARK_INTR && (flags & _PY_FAIL_IF_INTERRUPTED)) {
123+
return PY_LOCK_INTR;
124+
}
122125
else if (ret == Py_PARK_TIMEOUT) {
123126
assert(timeout >= 0);
124127
return PY_LOCK_FAILURE;

Python/thread.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ PyThread_acquire_lock_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds,
119119

120120
_PyLockFlags flags = _Py_LOCK_DONT_DETACH;
121121
if (intr_flag) {
122-
flags |= _PY_LOCK_HANDLE_SIGNALS;
122+
flags |= _PY_FAIL_IF_INTERRUPTED;
123123
}
124124

125125
return _PyMutex_LockTimed((PyMutex *)lock, timeout, flags);

0 commit comments

Comments
 (0)