Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #10702

Re: Notifications when process is killed

References <mailman.1730.1312213173.1164.python-list@python.org> <a4209f40-8bac-48e5-9092-3cf9d68055ef@g2g2000vbl.googlegroups.com>
Date 2011-08-02 10:01 +0100
Subject Re: Notifications when process is killed
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1752.1312275689.1164.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web