@@ -510,8 +510,7 @@ ThreadHandle_join(ThreadHandle *self, PyTime_t timeout_ns)
510
510
// To work around this, we set `thread_is_exiting` immediately before
511
511
// `thread_run` returns. We can be sure that we are not attempting to join
512
512
// 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 )) {
515
514
if (ThreadHandle_ident (self ) == PyThread_get_thread_ident_ex ()) {
516
515
// PyThread_join_thread() would deadlock or error out.
517
516
PyErr_SetString (ThreadError , "Cannot join current thread" );
@@ -520,36 +519,34 @@ ThreadHandle_join(ThreadHandle *self, PyTime_t timeout_ns)
520
519
if (Py_IsFinalizing ()) {
521
520
// gh-123940: On finalization, other threads are prevented from
522
521
// running Python code. They cannot finalize themselves,
523
- // so join() would hang forever.
522
+ // so join() would hang forever (or until timeout) .
524
523
// We raise instead.
525
- // (We only do this if no timeout is given: otherwise
526
- // we assume the caller can handle a hung thread.)
527
524
PyErr_SetString (PyExc_PythonFinalizationError ,
528
525
"cannot join thread at interpreter shutdown" );
529
526
return -1 ;
530
527
}
528
+ }
531
529
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
+ }
541
539
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 ;
551
544
}
552
545
}
546
+ else {
547
+ // Timed out
548
+ return 0 ;
549
+ }
553
550
}
554
551
555
552
if (_PyOnceFlag_CallOnce (& self -> once , (_Py_once_fn_t * )join_thread ,
0 commit comments