threading module oddness

Jason Orendorff jason at jorendorff.com
Thu Dec 13 06:26:17 EST 2001


I've been kicking around in the threading.py source code.

Two things:

1. In Condition, I noticed this code:

class _Condition:
    ...
    def _is_owned(self):
        if self.__lock.acquire(0):
            self.__lock.release()
            return 0
        else:
            return 1

According to the current documentation for the 'thread' module,
the lock object should have a locked() method:

    def _is_owned(self):
        return self.__lock.locked()


2.  Wow, I had no idea what was going on under the hood here.
Especially Condition.wait().  Wouldn't it be better if all this
stuff were implemented using the native primitives?  How would a
patch for that be received, assuming I could only help out with
1 or 2 platforms (pthread and NT)?  (The rest could fall back on
the current Python implementation for now.)

-- 
Jason Orendorff





More information about the Python-list mailing list