Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!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; '22,': 0.09; 'executed': 0.09; 'main()': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; '2.7': 0.14; 'creates': 0.14; 'block.': 0.16; 'blocks': 0.16; 'called.': 0.16; 'elsewhere.': 0.16; 'handlers': 0.16; 'reasonably': 0.16; 'respond.': 0.16; 'skip:" 70': 0.16; 'threads.': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'trying': 0.19; 'seems': 0.21; 'issue.': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'error': 0.23; 'versions': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'url:bugs': 0.29; 'am,': 0.29; 'raise': 0.29; "doesn't": 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'code': 0.31; '13,': 0.31; 'behaving': 0.31; 'catching': 0.31; 'filed': 0.31; 'terminate': 0.31; 'file': 0.32; 'run': 0.32; 'open': 0.33; 'url:python': 0.33; '(most': 0.33; 'skip:_ 10': 0.34; 'skip:s 30': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'raising': 0.36; 'url:listinfo': 0.36; 'method': 0.36; 'charset:us-ascii': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'should': 0.36; 'changing': 0.37; 'message- id:@gmail.com': 0.38; 'thank': 0.38; 'e.g.': 0.38; 'issue': 0.38; 'recent': 0.39; 'sure': 0.39; 'called': 0.40; 'url:mail': 0.40; 'signal': 0.60; 'free': 0.61; 'mentioned': 0.61; 'further': 0.61; 'header:Message-Id:1': 0.63; '30,': 0.65; 'it!': 0.67; 'registers': 0.68; 'article': 0.77; 'here!': 0.84; 'interrupted': 0.96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=pRIUO7Xe+kVilWqB2erDVpDSv835nif4IOeIhznncwY=; b=ynIZJiZHdr60uROXt4vqq6FEbU771bnTac2b5NKdBL08Ndj7ce6yZRnkXzQOHckPEy 3A3NUusXFYsqn0nfEXsN1dehfzEdz2aHoif045yhoV6tAw7/HM5JlsULUOjBn5D0k0rN XN17Z4WFUVyDN3JxAcwxOo83K4ISthe2Ost8V5EF/gMfk6apbBKeYemQFMBL6XLyjlJb U5TjBwEyt71zKi1jJ4cfOWWRuxCZSh/KNMjK5MBXvN0SHPJNceIpA6ceHZxKZ7gSq1Jt td77eixW5EIesDuvlEOW9VGbFpuLw2iroxEPsWRDZwUmakBo7eIC+23CMa25b1R2c/ns xz3A== X-Received: by 10.70.42.109 with SMTP id n13mr7082940pdl.36.1404434884330; Thu, 03 Jul 2014 17:48:04 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.2\)) Subject: Re: threading.Condition.wait() is not catching SIGTERM From: Sangeeth Saravanaraj In-Reply-To: Date: Fri, 4 Jul 2014 06:18:00 +0530 Content-Transfer-Encoding: quoted-printable References: <17F05A1B-44C8-4F25-AFE9-5DBCFFB9982B@gmail.com> To: Ned Deily X-Mailer: Apple Mail (2.1878.2) Cc: python-list@python.org 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: 78 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1404434892 news.xs4all.nl 2901 [2001:888:2000:d::a6]:44609 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:73929 On 04-Jul-2014, at 1:43 am, Ned Deily wrote: > In article <17F05A1B-44C8-4F25-AFE9-5DBCFFB9982B@gmail.com>, >> I have the following code which when executed waits to be interrupted = by=20 >> SIGINT, SIGTERM or SIGQUIT. When an object is initialized, it creates = a=20 >> threading.Condition() and acquires() it! The program then registers = the=20 >> signal handlers where notify() and release() is called when the above=20= >> mentioned signals are received. After registering the signal = handlers, it=20 >> calls wait() on the condition variable and block. >>=20 >> When I tried to stop the program with Ctrl-C, its did not respond. = IOW, the=20 >> _signal_handler() method did not get called. =20 >=20 > I'm not sure what you are trying to do but your test case seems = flawed. =20 > threading.Condition is designed to be used with multiple threads but=20= > your test doesn't actually use threads. If you run your test with a=20= > reasonably current Python 3 (after changing print to print()), you can=20= > see that it fails (and why it fails) when interrupting with Ctrl-C: >=20 > Waiting to be interrupted! > ^CReceived terminate request - signal =3D 2 > Traceback (most recent call last): > File "b.py", line 30, in > main() > File "b.py", line 27, in main > a.register_and_wait() > File "b.py", line 22, in register_and_wait > self._termination_signal.wait() # control blocks here! > File=20 > = "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/threadin > g.py", line 289, in wait > waiter.acquire() > File "b.py", line 13, in _signal_handler > self._termination_signal.notify() > File=20 > = "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/threadin > g.py", line 339, in notify > raise RuntimeError("cannot notify on un-acquired lock") > RuntimeError: cannot notify on un-acquired lock >=20 > After a quick glance, I'm not sure why Python 2.7 is behaving=20 > differently, e.g. not raising an error, since both versions of=20 > Condition.notify have the same test so the difference is elsewhere. =20= > Feel free to open an issue for not catching the error in 2.7 but you=20= Ned, thanks for the explanation.=20 I have filed http://bugs.python.org/issue21913 to explore further on = this issue. Thank you, Sangeeth=20 > should rethink what you are trying to do here. >=20 > --=20 > Ned Deily, > nad@acm.org >=20 > --=20 > https://mail.python.org/mailman/listinfo/python-list