Avoid race condition with Popen.send_signal

Jérôme jerome at jolimont.fr
Tue Jan 3 10:09:36 EST 2012


Tue, 3 Jan 2012 06:12:59 -0800 (PST)
Adam Skutt a écrit:

> The conservative approach is to use another IPC mechanism to talk to
> the process, such as a pipe or a socket.  Why are you trying to send
> the child process SIGINT in the first place?

Say, you've got an application that plays a sound for a few seconds, using an
external program for that (beep, sox). If you close the application, you want
the sound to stop as well.

I don't know much about subprocess, not much more than what is in the
tutorial : http://docs.python.org/library/subprocess.html

(I don't know much about signalling either, I'm learning...)

I naively thought kill() was the "normal" way. Then realized terminate() or
even send_signal(SIGINT) would be softer.

What would be a good approach, then ?

Should I try something like this ?

	communicate(input="Ctrl+C")

(I'd need to figure out how to write Ctrl+C...)

Would that be cross-platform ?

-- 
Jérôme



More information about the Python-list mailing list