Issue 928332: Python interpreter stalled on _PyPclose.WaitForSingleObject (original) (raw)

Windows only:

You can easily block the whole interpreter by starting a lengthy/blocking external process with os.popenX:

import os, time, threading

def showtime(): while 1: print '.' time.sleep(1)

th1 = threading.Thread(None, showtime, None) th1.start() fo = os.popen('cscript waitforever.vbs', 'rt') res = fo.close() print 'ok'

waitforever.vbs has a single line: WScript.Sleep (2000000000) You will never reach print 'ok', which is the expected behaviour because fo.close() is waiting for the process to stop, something which will never happen. The problem is that the 'showtime' thread is also blocked ! Indeed, when looking with the debugger, we can see that the main thread is blocked in the _PyPclose.WaitForSingleObject call, but the GIL has not been released before entering this wait, so any other Python thread are blocked too. So I think that the GIL should be released before the WaitForSingleObject call. Also, something different from INFINITE as the second parameter may be appropriate (defined by the user, for eg, would be great)...