global threading.Lock not locking correctly?
Alex Martelli
aleax at aleax.it
Tue Feb 4 10:11:15 EST 2003
Afanasiy wrote:
> # My logic tells me this should never print 'OOPS', yet it does.
> # Can someone tell me why? (P.S. this is simplified example code)
>
> import threading, time
>
> class testthread(threading.Thread):
>
> def run(self):
> for x in range(40):
>
> global lock
> global visitors
>
> lock.acquire
>
> visitors += 1
> if visitors > 1:
> print 'OOPS!'+str(visitors),
> else:
> print '.',
> visitors -= 1
>
> lock.release
You're not CALLING the acquire and release methods, just
MENTIONING them. use lock.acquire() and lock.release().
Alex
More information about the Python-list
mailing list