I just upgraded to MacOS 11.2 which now uses Python 3.8.2. My test suite guarantees that printed output prints as the output is sent to the console by using the code snippet below. As verified by the print xxx or print yyy statements the code hangs after roughly 50 Unit Tests. This code has been working for roughly 4 years and of course was working just prior to the 11.2 system upgrade. Any ideas for work arounds would be appreciated.
print( '
running: ' + curFilePath.split('/')[-1] + ': ' + str(curVer))
p = subprocess.Popen(fullCMD, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while True: # Print output as it sent to console
print( 'xxx' )
nextline = p.stdout.readline().decode()
if nextline == '' and p.poll() is not None:
print( 'yyy' )
break
sys.stdout.write(nextline)
sys.stdout.flush()
print( 'completed: ' + curFilePath.split('/')[-1] )
question from:
https://stackoverflow.com/questions/66052620/pythons-3-8-2-subprocess-poll-hangs-after-being-called-40-or-50-times 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…