subprocess.Popen not replacing current process?

goodman goodman.m.w at
Fri Nov 5 00:48:25 CET 2010

On Nov 4, 1:22 am, goodman <goodman.... at> wrote:
> Note: Our server is a Linux machine, but we're restricted to Python
> 2.4.
> Hi, I'm wondering why subprocess.Popen does not seem to replace the
> current process, even when it uses os.execvp (according to the
> documentation:
> Specifically, when I try to kill a spawned process with Ctrl-C, the
> SIGINT does not seem to be sent to the spawned process.
> Some background: I have a Python script that calls shell scripts or
> commands. It does not need to regain control after calling these
> scripts or commands, so up to now I've been using an os.exec* command.
> It seems the subprocess module is the recommended way for spawning
> processes, but in this case perhaps it's better I stick with os.exec*?
> I've seen plenty of discussion about catching KeyboardInterrupt in the
> parent process and then manually killing the child, but (1) I can't
> use Popen.kill() on Python 2.4, and (2) this level of process
> management seems like overkill (pardon the potential for puns) in my
> case.
> Thanks for any help.

Following up, I can get the effect I want with the following:

  p = subprocess.Popen([cmd, arg1, arg2])
except KeyboardInterrupt:
  import signal
  os.kill(, signal.SIGKILL)

...but like I said, I don't think I should be managing this myself,
since I don't need to return from the new process. How can I make the
new process handle its own signals?

More information about the Python-list mailing list