pexpect/ptyprocess

Wait() should return normally if the child process has already terminated

reynir opened this issue · 5 comments

Calling wait() on a PtyProcess object whose process has already terminated will raise an exception. This behavior is unexpected[1].
I have made a small test to show case the behavior. Using p.isalive() && p.wait() will only make the race condition worse in my tests.

[1]: subprocess.Popen.wait() returns normally even when the process has already terminated, although it doesn't say so explicitly in the documentation. In java the waitFor() method "returns immediately if the subprocess has already terminated."

Maybe more importantly this is not the behavior of wait in expect(1)

agreed, fix + test case would be accepted.

I agree, but we should be careful with Pexpect, because this is its historical behaviour, and I don't think it's worth breaking backwards compatibility to change that. For ptyprocess, which is a new API, it absolutely makes sense to follow conventions more, though.

Thanks for acknowledging.

Became PR #18, and in pexpect, pexpect/pexpect#211

Lets allow those open PR's to address any further comments and close this one. Thanks again @reynir !