KeyboardInterrupt in Subproccesses

Matthew Lefavor mclefavor at gmail.com
Thu Jul 18 20:44:36 CEST 2013


All:

I am maintaining a program in Python 2 and need to send it a
KeyboardInterrupt to close it. Unfortunately, the program is used as a
subprocess in a wrapper subprocess, and so I cannot just directly press
CTL-C; I have to use a signal.

When I run the program "bare" (not in a subprocess), I have found that
raising a SIGINT (kill -2) raises a KeyboardInterrupt in the program. But
when I run the program in the wrapper process, kill -2 no longer has any
effect (whether it is raised by the wrapper or externally).

Why is that the case? Does Python's interpretation of SIGINT as a
KeyboardInterrupt only obtain when the program is run in a terminal? Is
there something else I'm missing?

Bonus points: Is this behavior the same for Python 3?

MCL
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130718/0c7b0258/attachment.html>


More information about the Python-list mailing list