I’m using python 3.6.8 and I have a situation when one process cannot continue until other one is finished.
- p1 is in the main thread and must stay opened for a long time doing things.
- p2 must run in separate thread (daemon=True), read stdout/err using communicate() and finish.
(all pipes are needed, must not disable them)
As you will see below, when run code by python 3.10.4 I have output “thread.popen/communicate”, but python 3.6.8 will not print this line.
it will stuck inside communicate() i think.
What I ask for is I need a workaround for 3.6.8 and optionally explanation what is going on with Python 3.6.8? a bug with Locks or maybe Pipes?
import threading from time import sleep from subprocess import Popen, PIPE, STDOUT def run(): print('thread') p2 = Popen('git', stdin = PIPE, stdout = PIPE, stderr = PIPE) o,e = p2.communicate() print('thread.popen/communicate') if __name__ == '__main__': threading.Thread(target=run, daemon=True).start() p1 = Popen('cmd', stdin = PIPE, stdout = PIPE, stderr = STDOUT) print('main.popen') # p1.wait() sleep(2)
F:\MySSDPrograms\cudatext\py\cuda_lsp>python.exe new.py thread main.popen thread.popen/communicate F:\MySSDPrograms\cudatext\py\cuda_lsp>f:\Python36\python.exe new.py thread main.popen