Fix deadlock when subprocess doesn't end with EOF#119
Fix deadlock when subprocess doesn't end with EOF#119davidlatwe wants to merge 1 commit intomottosso:masterfrom
Conversation
Oh, did the other solution not work in the end?
My guess would be it has to do with the resolved environment running in either cmd.exe or powershell.exe. One of those should probably yield a different result, and I bet it isn't an issue on Linux. |
Somehow it still works, but not broadly tested and I still don't understand why it works. for line in iter(self.popen.stdout.readline, ""):
if not line:
continue
...Still not knowing why continuing the loop when the And this PR, at least I know how it works.
But at the time when I opened #104, I was on Mac, launching Allzpark in Rez resolved context. :P |
This PR is for fixing the same problem what #104 have, but with another solution.
Problem
Deadlock occurred when we use
stdout.readlineto listen to thesubprocessthat doesn't end with EOF.I found that my Allzpark will freeze when closing the application that it just launched, IF Allzpark was launched from a Rez resolved context. And the freeze was because the
stdout.readlinekeep sending empty lineb""due to no EOF signal.So why there has no EOF emitted from subprocess when Allzpark is launched from a resolved context ? I haven't figure it out. :(
It seems like
cmd.exein subprocess is not able to send EOF, not sure.Here's a simple reproducible :
Nevertheless, I came up a solution that seems solid. 🤔
I have changed the
stderrlistening function to act likePopen.communicate(), since I thinkstderrdoesn't need to be streamed.(Referenced from Python's
subprocess.py)With that we can know when the subprocess is ended, and send our own EOF flag to the
stdoutlistening thread to make it stop . Problem solved.