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 pitrou
Recipients JohanAR, davin, gvanrossum, itamarst, ncoghlan, pitrou, python-dev, rhettinger, sbt, serhiy.storchaka, tim.peters, yselivanov, zzzeek
Date 2017-08-18.15:51:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
In-reply-to <>
Le 18/08/2017 à 17:37, Yury Selivanov a écrit :
> Is it guaranteed that the GC will happen in the same thread that is holding the lock?

By design, if it's called from a different thread, Queue will cope fine:
__del__ implicitly calls RLock.acquire which, if the RLock is already
taken, releases the GIL and waits until the RLock is released by the
other thread.

The contentious case is when a Queue method call is interrupted by some
asychronous event (signal handler, GC callback) that calls another Queue
method in the same thread.

Note, in my patch, the RLock isn't even used for its recursive
properties, but only because it allows to query if it's already taken by
the current thread (using a private method that's already used by
threading.Condition, and which could reasonably be made public IMHO).

(on that topic, the pure Python implementation of RLock doesn't
guarantee proper reentrancy against asynchronous events itself -- see --, but fortunately we use a C
implementation by default which is pretty much ok)
Date User Action Args
2017-08-18 15:51:40pitrousetrecipients: + pitrou, gvanrossum, tim.peters, rhettinger, ncoghlan, zzzeek, python-dev, sbt, serhiy.storchaka, JohanAR, yselivanov, itamarst, davin
2017-08-18 15:51:40pitroulinkissue14976 messages
2017-08-18 15:51:40pitroucreate