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.

classification
Title: cpython/lib/queue.py: put() does not acquire not_empty before notifying on it
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.10, Python 3.9, Python 3.8, Python 3.7, Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: r n2, rhettinger, tim.peters
Priority: normal Keywords:

Created on 2020-06-08 06:59 by r n2, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg371147 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2020-06-10 00:50
This code looks correct to me.  For condition variables, the requirement is that the underlying lock be held when notify() is called.  The not_full and not_empty condition variables share the same underlying lock, so it is sufficient that not_empty.notify() is called inside the body of "with self.not_full".
msg371150 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2020-06-10 01:23
Also note that threading.Condition.notify() would raise a RuntimeError if the underlying lock had not been acquired.

Have you observed any behavior to the contrary?
msg371162 - (view) Author: r n (r n2) Date: 2020-06-10 06:03
Thanks for the response.
However, if you see, every condition object has their own queue of waiters in self._waiters, that get notified during notify(), which are different for not_empty and not_full.
I see a hang very very rarely, like 1/25 times, in my program, which keeps, reading from and writing to a queue from multiple threads.
msg371164 - (view) Author: r n (r n2) Date: 2020-06-10 06:08
Sorry, please ignore my previous comment, I can see that the issue is not in the queue, but probably be somewhere in my setup. 
I'll close this bug therefore. Thanks again for the clarification.
History
Date User Action Args
2022-04-11 14:59:32adminsetgithub: 85084
2020-06-10 06:08:40r n2setstatus: open -> closed
resolution: not a bug
messages: + msg371164

stage: resolved
2020-06-10 06:03:58r n2setnosy: + r n2
messages: + msg371162
2020-06-10 01:23:53rhettingersetmessages: + msg371150
2020-06-10 00:50:54rhettingersetnosy: + tim.peters
messages: + msg371147
2020-06-09 14:58:22r n2setversions: + Python 3.9, Python 3.10
2020-06-08 21:05:03r n2setnosy: + rhettinger, - r n2
title: cpython/queue.py: put() does not acquire not_empty before notifying on it -> cpython/lib/queue.py: put() does not acquire not_empty before notifying on it
2020-06-08 07:03:33r n2settitle: cpython/queue.py: put() does not acquire not_empty lock before notifying on it -> cpython/queue.py: put() does not acquire not_empty before notifying on it
2020-06-08 07:03:03r n2setversions: + Python 3.6, Python 3.7
2020-06-08 06:59:47r n2create