an error in python lib?

MRAB python at mrabarnett.plus.com
Tue Oct 9 21:16:46 EDT 2012


On 2012-10-10 01:32, Wenhua Zhao wrote:
> Hi list,
>
> I just noticed that in /usr/lib/python2.7/threading.py
>
> class _Condition(_Verbose):
>      ...
>      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
>
> The return values seem to be wrong.  They should be swapped:
>
>      def _is_owned(self):
>          if self.__lock.acquire(0):
>              self.__lock.release()
>              return True
>          else:
>              return False
>
> Or I understood it wrong here?
>
The .acquire method will return True if the attempt to acquire has been
successful. This can occur only if it is not currently owned.

In pseudocode:

if the attempt to acquire it succeeds:
     no-one owed it before, but now I own it
     release it
     now no-one owns it
     return False
else:
     someone already owns it
     return True




More information about the Python-list mailing list