This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author josh.r
Recipients josh.r, pitrou, sangeeth
Date 2014-07-04.01:32:57
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1404437578.11.0.959006473409.issue21913@psf.upfronthosting.co.za>
In-reply-to
Content
So you want it to raise the same exception that is raised in Python 3.4? Either way, I don't think this is a deadlock (to get a deadlock, you'd have to have contested locks; this lock is being acquired only once). You're explicitly violating the rules of using Conditions.

To be precise, you:

1. Acquire the Condition's lock in the main thread (legal, if odd to do in the constructor)
2. Call the Condition's wait method (legal; you acquired the lock so you can wait)
3. (Implicit) By wait-ing, you implicitly release the lock
4. At some point, you hit Ctrl-C. If the signal handler is called as expected, it will try to call Condition.notify(), which is illegal, because the lock was released as a side-effect of calling Condition.wait() earlier.

So best case scenario, this code is wrong. The fact that it doesn't work correctly in Python 2.7 is an issue, but the possible reasons go well beyond deadlocks; you've written code that is guaranteed to be wrong (throw RuntimeExceptions) even if all goes according to plan.

Do you get more reasonable behavior if you write the class as:

class A:
    def __init__(self):
        self._termination_signal = Condition()

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

    def register_and_wait(self):
        with self._termination_signal:
            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!!"
History
Date User Action Args
2014-07-04 01:32:58josh.rsetrecipients: + josh.r, pitrou, sangeeth
2014-07-04 01:32:58josh.rsetmessageid: <1404437578.11.0.959006473409.issue21913@psf.upfronthosting.co.za>
2014-07-04 01:32:58josh.rlinkissue21913 messages
2014-07-04 01:32:57josh.rcreate