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 dcoles
Recipients dcoles, gvanrossum, vstinner, yselivanov
Date 2015-01-15.02:16:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1421288180.98.0.524650298649.issue22970@psf.upfronthosting.co.za>
In-reply-to
Content
Hi Victor,

(Sorry for the delay, I think GMail ate the notification)

The main issue is that Condition.wait MUST reacquire the associated lock released on entry to wait() before returning or else the caller's assumption that it holds a lock (such as `with lock:`) will be incorrect.

With the threading module, it's typically not possible to interrupt or cancel lock acquisition (no Thread.interrupt for example). Even on Python 3.2 where lock acquisition can be interrupted by POSIX signals, Condition.wait's implementation uses the non-interruptable lock._acquire_restore (calls rlock_acquire_restore →  PyThread_acquire_lock → PyThread_acquire_lock → PyThread_acquire_lock_timed with intr=0 [Python/thread_pthread.h] which does the uninterruptable retry loop). So, not a problem for threading.Condition.wait().

As for re-raising the CancelledError after the lock is reacquired, I'm not sure it serves any useful purpose to the caller since by this point we're either in the process of waking up after a notify() or already raising an exception (such as a CancelledError if someone called task.cancel() _before_ the condition was notified). Making the caller also handle re-acquisition failure would be quite messy.

For example, one idea would be to have the caller check cond.locked() after a CancelledError and have the caller reacquire, but it turns in asyncio you can't tell whom owns the lock (could have been grabbed by another task).
History
Date User Action Args
2015-01-15 02:16:21dcolessetrecipients: + dcoles, gvanrossum, vstinner, yselivanov
2015-01-15 02:16:20dcolessetmessageid: <1421288180.98.0.524650298649.issue22970@psf.upfronthosting.co.za>
2015-01-15 02:16:20dcoleslinkissue22970 messages
2015-01-15 02:16:18dcolescreate