Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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:not': 0.03; '"__main__":': 0.09; '__name__': 0.09; 'executed': 0.09; 'main()': 0.09; 'def': 0.12; 'creates': 0.14; 'a()': 0.16; 'block.': 0.16; 'blocks': 0.16; 'called.': 0.16; 'handlers': 0.16; 'main():': 0.16; 'received:192.168.128': 0.16; 'respond.': 0.16; 'variable': 0.18; 'all,': 0.19; 'import': 0.22; 'print': 0.22; 'skip:_ 20': 0.27; 'tried': 0.27; 'code': 0.31; 'terminate': 0.31; 'class': 0.32; 'skip:_ 10': 0.34; 'skip:s 30': 0.35; 'received:google.com': 0.35; 'doing': 0.36; 'method': 0.36; 'charset:us-ascii': 0.36; 'message-id:@gmail.com': 0.38; 'thank': 0.38; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'called': 0.40; 'signal': 0.60; 'mentioned': 0.61; 'header:Message-Id:1': 0.63; 'it!': 0.67; 'registers': 0.68; 'here!': 0.84; 'interrupted': 0.96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:content-type:subject:message-id:date:to:mime-version; bh=a8FiqKESQeBFS76yG//TJmpjz/DaykQBBuy7uvRFYYc=; b=paXLWI5x/5mDr1IiThkJkekstqXfttCh6QNv9HApo7A3IzFjK/vVfTUG1h9tmo4oPh HztJ3wuQcmZJ+Z5g0QK3Jl/VP8Fkwazz+OyNdb85Dqjdr6HuxgiRMZPBZLRrVYNw2j5+ 8Y/EbPxWwS96iWm1HvHeIpqW7LvePKFMQ7UpyQI/n0UtHX4FuhlhJIGrnnqSrPIcLd6D WDQlzfSmcgPmNZI8ysXh6VUsf9VikhtuxVJbS/67tEo45T+UiqpJVa96cvDf/IAB3eRp XNd/x6w628+XsH7yaGY0C9OhjTdQYBttMVro/UIBtEcdWbeZw1BGXKhqAqU0zqvQLyxG PKgw== X-Received: by 10.66.234.202 with SMTP id ug10mr3574686pac.109.1404382543393; Thu, 03 Jul 2014 03:15:43 -0700 (PDT) From: Sangeeth Saravanaraj Content-Type: multipart/alternative; boundary="Apple-Mail=_7F87B4DE-9EBA-4CD1-A203-73BF6243FB3B" Subject: threading.Condition.wait() is not catching SIGTERM Date: Thu, 3 Jul 2014 15:45:38 +0530 To: python-list@python.org Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.2\)) X-Mailer: Apple Mail (2.1878.2) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 130 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1404382552 news.xs4all.nl 2908 [2001:888:2000:d::a6]:39628 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:73893 --Apple-Mail=_7F87B4DE-9EBA-4CD1-A203-73BF6243FB3B Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Hi All,=20 I have the following code which when executed waits to be interrupted by = SIGINT, SIGTERM or SIGQUIT. When an object is initialized, it creates a = threading.Condition() and acquires() it! The program then registers the = signal handlers where notify() and release() is called when the above = mentioned signals are received. After registering the signal handlers, = it calls wait() on the condition variable and block. When I tried to stop the program with Ctrl-C, its did not respond. IOW, = the _signal_handler() method did not get called. =20 # start from signal import signal, SIGINT, SIGTERM, SIGQUIT from threading import Condition class A: def __init__(self): self._termination_signal =3D Condition() self._termination_signal.acquire(blocking=3D0) def _signal_handler(self, signum, frame): print "Received terminate request - signal =3D = {0}".format(signum) del frame self._termination_signal.notify() self._termination_signal.release() return def register_and_wait(self): signal(SIGINT, self._signal_handler) signal(SIGTERM, self._signal_handler) signal(SIGQUIT, self._signal_handler) print "Waiting to be interrupted!" self._termination_signal.wait() # control blocks here! print "Notified!!" def main(): a =3D A() a.register_and_wait() if __name__ =3D=3D "__main__": main() # end What am I doing wrong?!=20 Thank you, Sangeeth= --Apple-Mail=_7F87B4DE-9EBA-4CD1-A203-73BF6243FB3B Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii Hi = All, 

I have the following code which when = executed waits to be interrupted by SIGINT, SIGTERM or SIGQUIT. = When an object is initialized, it creates a threading.Condition() and = acquires() it! The program then registers the signal handlers where = notify() and release() is called when the above mentioned signals are = received. After registering the signal handlers, it calls wait() on the = condition variable and block.

When I tried to = stop the program with Ctrl-C, its did not respond. IOW, the = _signal_handler() method did not get called. =  

# = start

from = signal import signal, SIGINT, SIGTERM, SIGQUIT
from threading import = Condition

class = A:
    def = __init__(self):
  =       self._termination_signal =3D = Condition()
  =       = self._termination_signal.acquire(blocking=3D0)

    def _signal_handler(self, signum, = frame):
    =     print "Received terminate request - signal =3D = {0}".format(signum)
        del frame
        = self._termination_signal.notify()
        = self._termination_signal.release()
        return

    def = register_and_wait(self):
        signal(SIGINT, = self._signal_handler)
        signal(SIGTERM, = self._signal_handler)
        signal(SIGQUIT, = self._signal_handler)
        print "Waiting to be = interrupted!"
  =       self._termination_signal.wait()     =  # control blocks here!
        print = "Notified!!"

def = main():
    = a =3D A()
  =   a.register_and_wait()

if = __name__ =3D=3D "__main__":
    main()

# end

What am I doing = wrong?! 

Thank = you,

Sangeeth
= --Apple-Mail=_7F87B4DE-9EBA-4CD1-A203-73BF6243FB3B--