Static lock in Python?
- by roddik
Hello. I've got the following code:
import time
import threading
class BaseWrapper: #static class
lock = threading.Lock()
@staticmethod
def synchronized_def():
BaseWrapper.lock.acquire()
time.sleep(5)
BaseWrapper.lock.release()
def test():
print time.ctime()
if __name__ is '__main__':
for i in xrange(10):
threading.Thread(target = test).start()
I want to have a method synchronized using static lock. However the above code prints the same time ten times, so it isn't really locking. How can I fix it? TIA