exception in child process propagates

Issue #3 new
Brian May created an issue

The code, simplified, is:

def _spawn(self,command,args=[]):
    ...
    if self.pid == 0: # Child
        ...
        os.exec...(...)

If an exception occurs if this child section, e.g. exec fails or any of the other instructions, the propagation is passed upwards to the caller, which is confusing because this is not the process that called the function. i.e. two processes return when you only expect one process to return.

This can be fixed by changing the child code to exit on exception:

def _spawn(self,command,args=[]):
    ...
    if self.pid == 0: # Child
        try:
            ...
            os.exec...(...)
        finally:
             sys.exit(1)

Note I have used finally here as exec should never return. So finally will only get executed if something went wrong.

Comments (3)

  1. Thomas Kluyver repo owner

    I'm not really maintaining this fork at the moment - I'm not convinced by the approach I took, and I don't use it enough myself to want to spend the time it would need to do a good job of it.

    The original author of pexpect got as far as putting it on Github, but apparently he's busy with fatherhood, and also isn't working on it.

    I might find time to help with another fork, if someone wants to do one. But I'd recommend starting from the code on Github, not this fork, and taking more care with backwards compatibility.

  2. Log in to comment