Because of multithreading semantics, this is not reliable.
Christophe
chris.cavalaria at free.fr
Thu May 4 04:48:33 EDT 2006
OlafMeding at gmail.com a écrit :
> Tim and Grant
>
>
> if q.empty():
> return
>
>
> Of course you explanation is understood and ideally should be included
> as a note in the Python documentation. And the "not reliable" should
> be removed from the documentation!
>
> Anyway, many thanks for your explanations (I feel "safer" now).
>
> Olaf
>
You could go as far as to say that since the function return itself
isn't wrapped in a mutex, the value can be obsolete before even the
function returns.
ie that code can sometimes return the wrong value :
def empty(self):
self.acquire_mutex()
result = self.count == 0
self.release_mutex()
return result before that line, some other thread added a value !
More information about the Python-list
mailing list