Skip to content

Commit d99b42b

Browse files
committed
Reduce diff
1 parent e463cb8 commit d99b42b

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

Modules/_threadmodule.c

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,7 @@ ThreadHandle_join(ThreadHandle *self, PyTime_t timeout_ns)
510510
// To work around this, we set `thread_is_exiting` immediately before
511511
// `thread_run` returns. We can be sure that we are not attempting to join
512512
// ourselves if the handle's thread is about to exit.
513-
PyEvent *is_exiting = &self->thread_is_exiting;
514-
if (!_PyEvent_IsSet(is_exiting)) {
513+
if (!_PyEvent_IsSet(&self->thread_is_exiting)) {
515514
if (ThreadHandle_ident(self) == PyThread_get_thread_ident_ex()) {
516515
// PyThread_join_thread() would deadlock or error out.
517516
PyErr_SetString(ThreadError, "Cannot join current thread");
@@ -520,36 +519,34 @@ ThreadHandle_join(ThreadHandle *self, PyTime_t timeout_ns)
520519
if (Py_IsFinalizing()) {
521520
// gh-123940: On finalization, other threads are prevented from
522521
// running Python code. They cannot finalize themselves,
523-
// so join() would hang forever.
522+
// so join() would hang forever (or until timeout).
524523
// We raise instead.
525-
// (We only do this if no timeout is given: otherwise
526-
// we assume the caller can handle a hung thread.)
527524
PyErr_SetString(PyExc_PythonFinalizationError,
528525
"cannot join thread at interpreter shutdown");
529526
return -1;
530527
}
528+
}
531529

532-
// Wait until the deadline for the thread to exit.
533-
PyTime_t deadline = timeout_ns != -1 ? _PyDeadline_Init(timeout_ns) : 0;
534-
int detach = 1;
535-
while (!PyEvent_WaitTimed(is_exiting, timeout_ns, detach)) {
536-
if (deadline) {
537-
// _PyDeadline_Get will return a negative value if
538-
// the deadline has been exceeded.
539-
timeout_ns = Py_MAX(_PyDeadline_Get(deadline), 0);
540-
}
530+
// Wait until the deadline for the thread to exit.
531+
PyTime_t deadline = timeout_ns != -1 ? _PyDeadline_Init(timeout_ns) : 0;
532+
int detach = 1;
533+
while (!PyEvent_WaitTimed(&self->thread_is_exiting, timeout_ns, detach)) {
534+
if (deadline) {
535+
// _PyDeadline_Get will return a negative value if the deadline has
536+
// been exceeded.
537+
timeout_ns = Py_MAX(_PyDeadline_Get(deadline), 0);
538+
}
541539

542-
if (timeout_ns) {
543-
// Interrupted
544-
if (Py_MakePendingCalls() < 0) {
545-
return -1;
546-
}
547-
}
548-
else {
549-
// Timed out
550-
return 0;
540+
if (timeout_ns) {
541+
// Interrupted
542+
if (Py_MakePendingCalls() < 0) {
543+
return -1;
551544
}
552545
}
546+
else {
547+
// Timed out
548+
return 0;
549+
}
553550
}
554551

555552
if (_PyOnceFlag_CallOnce(&self->once, (_Py_once_fn_t *)join_thread,

0 commit comments

Comments
 (0)