Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #18355
| Date | 2012-01-03 00:09 +0100 |
|---|---|
| From | Jérôme <jerome@jolimont.fr> |
| Subject | Avoid race condition with Popen.send_signal |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4323.1325545598.27778.python-list@python.org> (permalink) |
Hi all.
When a subprocess is running, it can be sent a signal with the send_signal
method :
process = Popen( args)
process.send_signal(signal.SIGINT)
If the SIGINT is sent while the process has already finished, an error is
raised :
File "/usr/lib/python2.7/subprocess.py", line 1457, in send_signal
os.kill(self.pid, sig)
OSError: [Errno 3] Aucun processus de ce type
To avoid this, I can check that the process is still alive :
process = Popen( args)
process.poll()
if (None == process.returncode):
process.send_signal(signal.SIGINT)
It makes safer, but there is still an issue if the process ends between
poll() and send_signal().
What is the clean way to avoid this race condition ?
Should I use try/except to catch the error or is there a more elegant way to
go ?
Thanks.
--
Jérôme
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Avoid race condition with Popen.send_signal Jérôme <jerome@jolimont.fr> - 2012-01-03 00:09 +0100
Re: Avoid race condition with Popen.send_signal Adam Skutt <askutt@gmail.com> - 2012-01-02 17:19 -0800
Re: Avoid race condition with Popen.send_signal Heiko Wundram <modelnine@modelnine.org> - 2012-01-03 13:31 +0100
Re: Avoid race condition with Popen.send_signal Adam Skutt <askutt@gmail.com> - 2012-01-03 05:40 -0800
Re: Avoid race condition with Popen.send_signal Heiko Wundram <modelnine@modelnine.org> - 2012-01-03 14:56 +0100
csiph-web