I can't get RLock to work (warning, the following code is pretty long)
__peter__ at web.de
Fri Apr 10 15:48:45 CEST 2009
> When I run the following...
> import time
> import thread
> import threading
> def get_first_part(string, lock, sleeptime, *args):
> global counter
> counter = counter + 1
> data = counter
> print "%s value is %d" % (string, counter)
> return data
> def get_both_parts(string, lock, sleeptime, *args):
> global first, second
> first = get_first_part()
> second = get_second_part()
> print "%s values are %d and %d" % (string, first,
> return first, second
> How come RLock isn't working in this example?
When get_both_parts() acquires the lock it invokes get_first_part() which
tries to acquire the lock. This fails because get_both_parts() does not
release the lock until after get_first_part() has finished...
More information about the Python-list