Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #10674 > unrolled thread
| Started by | Andrea Di Mario <anddimario@gmail.com> |
|---|---|
| First post | 2011-08-01 17:39 +0200 |
| Last post | 2011-08-03 20:41 -0700 |
| Articles | 7 — 6 participants |
Back to article view | Back to comp.lang.python
Notifications when process is killed Andrea Di Mario <anddimario@gmail.com> - 2011-08-01 17:39 +0200
Re: Notifications when process is killed AndDM <anddimario@gmail.com> - 2011-08-02 00:30 -0700
Re: Notifications when process is killed Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-08-02 10:26 +0200
Re: Notifications when process is killed Kushal Kumaran <kushal.kumaran+python@gmail.com> - 2011-08-02 16:45 +0530
Re: Notifications when process is killed Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-08-02 13:40 +0200
Re: Notifications when process is killed Chris Angelico <rosuav@gmail.com> - 2011-08-02 10:01 +0100
Re: Notifications when process is killed chrisallick <chrisallick@gmail.com> - 2011-08-03 20:41 -0700
| From | Andrea Di Mario <anddimario@gmail.com> |
|---|---|
| Date | 2011-08-01 17:39 +0200 |
| Subject | Notifications when process is killed |
| Message-ID | <mailman.1730.1312213173.1164.python-list@python.org> |
Thanks Thomas, it is what i'm looking for. Regards -- Andrea Di Mario
[toc] | [next] | [standalone]
| From | AndDM <anddimario@gmail.com> |
|---|---|
| Date | 2011-08-02 00:30 -0700 |
| Message-ID | <a4209f40-8bac-48e5-9092-3cf9d68055ef@g2g2000vbl.googlegroups.com> |
| In reply to | #10674 |
On Aug 1, 5:39 pm, Andrea Di Mario <anddima...@gmail.com> wrote:
> Thanks Thomas, it is what i'm looking for.
>
> Regards
>
> --
> Andrea Di Mario
Hi, i've a little problem, here the code that i use:
def receive_signal(signum, stack):
logging.info('Received: %s' % signum)
reactor.stop()
signal.signal(signal.SIGTERM, receive_signal)
signal.signal(signal.SIGHUP, receive_signal)
signal.signal(signal.SIGINT, receive_signal)
The function works for SIGHUP and SIGINT, but it doesn't work for
SIGTERM. I've tried with simple killall and with -15 option.
Have you some ideas?
Thanks, regards.
[toc] | [prev] | [next] | [standalone]
| From | Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> |
|---|---|
| Date | 2011-08-02 10:26 +0200 |
| Message-ID | <j18cbk$up0$1@r03.glglgl.eu> |
| In reply to | #10698 |
Am 02.08.2011 09:30 schrieb AndDM: > The function works for SIGHUP and SIGINT, but it doesn't work for > SIGTERM. I've tried with simple killall and with -15 option. > Have you some ideas? SIGTERM cannot be caught - it kills the process the hard way. HTH, Thomas
[toc] | [prev] | [next] | [standalone]
| From | Kushal Kumaran <kushal.kumaran+python@gmail.com> |
|---|---|
| Date | 2011-08-02 16:45 +0530 |
| Message-ID | <mailman.1763.1312283739.1164.python-list@python.org> |
| In reply to | #10701 |
On Tue, Aug 2, 2011 at 1:56 PM, Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> wrote: > Am 02.08.2011 09:30 schrieb AndDM: > >> The function works for SIGHUP and SIGINT, but it doesn't work for >> SIGTERM. I've tried with simple killall and with -15 option. >> Have you some ideas? > > SIGTERM cannot be caught - it kills the process the hard way. > You must mean SIGKILL. There's nothing special about SIGTERM, except that it's the default for the kill command. -- regards, kushal
[toc] | [prev] | [next] | [standalone]
| From | Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> |
|---|---|
| Date | 2011-08-02 13:40 +0200 |
| Message-ID | <j18nnc$6tu$1@r03.glglgl.eu> |
| In reply to | #10701 |
Am 02.08.2011 10:26 schrieb Thomas Rachel: > Am 02.08.2011 09:30 schrieb AndDM: > >> The function works for SIGHUP and SIGINT, but it doesn't work for >> SIGTERM. I've tried with simple killall and with -15 option. >> Have you some ideas? > > SIGTERM cannot be caught - it kills the process the hard way. Thank you for pointing out (via email) that this is wrong: SIGTERM is a normal signal which can be caught in the normal way. SIGKILL is (besides SIGSTOP) the one which cannot be caught, blocked or ignored. Thomas
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2011-08-02 10:01 +0100 |
| Message-ID | <mailman.1752.1312275689.1164.python-list@python.org> |
| In reply to | #10698 |
On Tue, Aug 2, 2011 at 8:30 AM, AndDM <anddimario@gmail.com> wrote:
> def receive_signal(signum, stack):
> logging.info('Received: %s' % signum)
> reactor.stop()
> signal.signal(signal.SIGTERM, receive_signal)
> signal.signal(signal.SIGHUP, receive_signal)
> signal.signal(signal.SIGINT, receive_signal)
>
> The function works for SIGHUP and SIGINT, but it doesn't work for
> SIGTERM. I've tried with simple killall and with -15 option.
> Have you some ideas?
You won't be able to catch SIGTERM, as Thomas said, but if you need to
know what caused a process to end, the best way is to have code in the
parent process to catch SIGCHLD. When the child ends, for any reason,
its parent is sent SIGCHLD with some parameters, including the signal
number that caused the termination; you can then log anything you
want.
Chris Angelico
[toc] | [prev] | [next] | [standalone]
| From | chrisallick <chrisallick@gmail.com> |
|---|---|
| Date | 2011-08-03 20:41 -0700 |
| Message-ID | <3c8e8fd8-5d52-44e7-a0d4-c48b5d2ae22a@en1g2000vbb.googlegroups.com> |
| In reply to | #10674 |
On Aug 1, 11:39 am, Andrea Di Mario <anddima...@gmail.com> wrote:
> Thanks Thomas, it is what i'm looking for.
>
> Regards
>
> --
> Andrea Di Mario
Catch a Kill:
def signal_handler(signal, frame):
print "Received exit command."
#server.running = False
sys.exit()
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
Find and Kill A Process:
import os, signal
process = "websocket.py"
found = False
for line in os.popen("ps ax | grep python"):
fields = line.split()
pid = fields[0]
for field in fields:
if field.find(process) >= 0:
print pid
print field
os.kill(int(pid), signal.SIGTERM)
found = True
break
if found == True:
break
if found == True:
print "found and killed web server process."
else:
print "could not find web server process.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web