Python threading

Brian Allen Vanderburg II BrianVanderburg2 at
Tue Jan 13 15:24:51 CET 2009

I'm doing some multi-threaded programming and before diving into the 
C/C++ code I though I'd do some in Python first.  I decided to read 
through the threading module and I understand some of it, but I don't 
understand this, though I'm sure it is easy:

The condition object has a method _is_owned, which is called if the lock 
doesn't have one.  The RLock does have one but a regular lock not.  It 
is supposed to return true if the lock is owned by the current thread:

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

It seems that for a condition without an RLock but a Lock, 
self.__lock.acquire(0) will return False even if the lock is owned by 
another thread other than the current thread, so _is_owned would return 
True even if the lock is owned by another thread.

B. Vanderburg II

More information about the Python-list mailing list