Fwd: Python becoming orphaned over ssh

David wizzardx at gmail.com
Fri Oct 1 15:43:12 CEST 2010


(Sending again to the list, I mailed Jean-Paul off-list by mistake, sorry).

On Thu, Sep 30, 2010 at 4:01 PM, Jean-Paul Calderone
<exarkun at twistedmatrix.com> wrote:
> You can fix this by resetting the signal disposition of SIGPIPE for
> the ping process:
>
>    #!/usr/bin/python
>    import signal
>
>    def reset():
>        signal.signal(signal.SIGPIPE, signal.SIG_DFL)
>
>    from subprocess import check_call
>    check_call(['ping', 'www.google.com'], preexec_fn=reset)
>
> Very likely the subprocess module should be resetting the disposition
> of signals that Python itself has fiddled with (and resetting any
> other unusual state that the child is going to inherit, but nothing
> else comes immediately to mind).
> --

Thanks, that works for me. Also  thanks to Gregory (Python developer)
for fixing it so quickly (don't want to litter the bug tracker with
thanks).

Small annoyance: Though it's fixed with ping, wget still has the
problem. However, I compared the two script versions again (test.sh,
and test.py) for wget, and actually bash has the same problem as
python, so I assume it's a wget bug this time (I'll go report the bug
to them next). Is it that unusual to run scripts over non-interactive
SSH, and then interrupt with Ctrl+C? :-). So I guess for now I need to
keep my previous workaround for now, rather than switching to the
preexec_fn syntax.

Also, I don't 100% follow that explanation about the pipes. I read a
bit more over here:

http://en.wikipedia.org/wiki/SIGPIPE

And it seems like SIGPIPE would apply in a case like this:

ping www.google.com | test.py

But I'm not calling ping like that. I guess it applies to regular
stream, non-piping operations, too? ie, something like this is
happening

[ping output] passes through==> [test.py] ==> passes through [ssh] ==>
passes through => [more ssh, bash, etc, up to my terminal]

And when ssh disappears, then Linux automatically sends ping SIGPIPE,
because it's output can no longer be "passed through" to anywhere.

Pretty interesting, but I'm a noob with this stuff. If I want to learn
more, would this WP article (and linked pages) be a good place to
learn more?

http://en.wikipedia.org/wiki/Signal_%28computing%29

Thanks,

David.



More information about the Python-list mailing list