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: threading.Condition can not work with threading.Semaphore
Type: behavior Stage: resolved
Components: Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: pitrou, rhettinger, tim.peters, 张晓林
Priority: normal Keywords:

Created on 2017-11-08 05:12 by 张晓林, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg305807 - (view) Author: 张晓林 (张晓林) Date: 2017-11-08 05:12
the python document say Condition work will Locks, like RLock...

but i find it not work with Semaphore, because Condition._is_owned is like this

    def _is_owned(self):
        # Return True if lock is owned by current_thread.
        # This method is called only if _lock doesn't have _is_owned().
        if self._lock.acquire(0):
            self._lock.release()
            return False
        else:
            return True

this work for RLock, but not work for Semaphore, and Semaphore do not have it's own _is_owned implement.

i spend a lot of time on this issue. maybe fix it, or document it out?
msg305910 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-11-08 21:29
Why do you want Condition to work with a Semaphore?  What would be achieved?

A Semaphore is not a lock, it's an other kind of concurrency primitive.  I don't think there's any point in detailing it any futrher.
msg305938 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2017-11-09 06:11
I concur with Antoine and don't think there is a real issue here to be solved.
History
Date User Action Args
2022-04-11 14:58:54adminsetgithub: 76158
2017-11-09 16:42:29pitrousetstatus: open -> closed
resolution: fixed
stage: resolved
2017-11-09 06:11:59rhettingersetnosy: + rhettinger
messages: + msg305938
2017-11-08 21:29:49pitrousetnosy: + pitrou, tim.peters
messages: + msg305910
2017-11-08 06:25:11张晓林settype: resource usage -> behavior
2017-11-08 05:12:05张晓林create