This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: [Win] Call subprocess.Popen() twice makes Thread.join() interruptible and deadlock
Type: behavior Stage: resolved
Components: Windows Versions: Python 3.9
process
Status: closed Resolution: duplicate
Dependencies: Superseder: [Windows] KeyboardInterrupt during Thread.join hangs that Thread
View: 21822
Assigned To: Nosy List: eryksun, paul.moore, steve.dower, tim.golden, zach.ware, zby1234
Priority: normal Keywords:

Created on 2021-03-05 16:16 by zby1234, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
joinbug.py zby1234, 2021-03-05 16:16
Messages (2)
msg388156 - (view) Author: Zhang Boyang (zby1234) Date: 2021-03-05 16:16
Please run joinbug.py and press Ctrl-C twice.

============= The output  =============

1st join
PLEASE PRESS CTRL-C TWICE, IGNORE THE 'Press any key to continue'
Press any key to continue . . . Press any key to continue . . .

thread exit
Traceback (most recent call last):
  File "D:\xxx\joinbug.py", line 21, in <module>
    t.join() # subprocess.Popen() makes join() can be interrupted
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python39\lib\threading.py", line 1033, in join
    self._wait_for_tstate_lock()
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python39\lib\threading.py", line 1049, in _wait_for_tstate_lock
    elif lock.acquire(block, timeout):
KeyboardInterrupt
2nd join
(stuck here)


============= Expected behaviour =============
either join uninterruptible
or the 2nd join doesn't deadlock.
msg388160 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2021-03-05 17:51
This is a variation on bpo-21822. If join() is called in the main thread, and it gets interrupted immediately after the lock.acquire(block, timeout) call, then subsequent calls will hang. In Windows, the acquire() call is not interruptible with Ctrl+C, so the KeyboardInterrupt gets raised immediately after acquire() returns, so the problem is easy to reproduce in Windows.
History
Date User Action Args
2022-04-11 14:59:42adminsetgithub: 87575
2021-03-05 17:51:25eryksunsetstatus: open -> closed

superseder: [Windows] KeyboardInterrupt during Thread.join hangs that Thread

nosy: + eryksun
messages: + msg388160
resolution: duplicate
stage: resolved
2021-03-05 16:16:07zby1234create