Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:process': 0.07; 'subject:when': 0.07; 'am,': 0.13; 'wrote:': 0.15; 'ends,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'ideas?': 0.16; 'parameters,': 0.16; '\xa0def': 0.16; 'aug': 0.19; 'received:209.85.210.174': 0.19; 'received:mail- iy0-f174.google.com': 0.19; "doesn't": 0.22; 'header:In-Reply- To:1': 0.22; 'end,': 0.23; 'reason,': 0.23; 'tue,': 0.23; 'code': 0.24; 'function': 0.26; 'tried': 0.27; 'message- id:@mail.gmail.com': 0.28; 'parent': 0.30; "won't": 0.32; 'chris': 0.32; 'skip:\xa0 30': 0.32; "i've": 0.33; 'to:addr:python-list': 0.34; '8bit%:3': 0.35; 'option.': 0.35; 'anything': 0.37; 'some': 0.37; 'but': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.38; 'signal': 0.38; 'to:addr:python.org': 0.39; 'received:209': 0.40; 'skip:r 20': 0.40; 'subject:skip:N 10': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=D1fJMvKn8AVXONiL/CbU43mdJ4PrsRg4qN9DEWKEH8M=; b=Vj+tg233VDgJNW60MXW5MDRqXl7m57YQzoW5whUfUn92y3rMrJohJu81zJjVxUiX8H fn7CJSYDntqTDo2MwovbTWW7w2LUhBSSEjAKdIFBTsSKVcptmX15aEL8n0t8J0hCfUjq LvEv24PALN9Q6vIWWPUc0zVYiUtDBAhmaWfZ4= MIME-Version: 1.0 In-Reply-To: References: Date: Tue, 2 Aug 2011 10:01:26 +0100 Subject: Re: Notifications when process is killed From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1312275689 news.xs4all.nl 23946 [2001:888:2000:d::a6]:52054 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:10702 On Tue, Aug 2, 2011 at 8:30 AM, AndDM wrote: > =A0 =A0 =A0 =A0def receive_signal(signum, stack): > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.info('Received: %s' % signum) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0reactor.stop() > =A0 =A0 =A0 =A0signal.signal(signal.SIGTERM, receive_signal) > =A0 =A0 =A0 =A0signal.signal(signal.SIGHUP, receive_signal) > =A0 =A0 =A0 =A0signal.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