Package concurrent_tree_crawler :: Package common :: Package threads :: Module sleep
[hide private]
[frames] | no frames]

Source Code for Module concurrent_tree_crawler.common.threads.sleep

 1  import threading 
 2   
3 -class Sleep:
4 """A counterpart of the C{time.sleep()} function. This implementation 5 allows some thread to wake up the sleeping thread. 6 """
7 - def __init__(self):
8 self.__cond = threading.Condition()
9
10 - def sleep(self, seconds):
11 self.__cond.acquire() 12 self.__cond.wait(seconds) 13 self.__cond.release()
14
15 - def wake_up(self):
16 self.__cond.acquire() 17 self.__cond.notifyAll() 18 self.__cond.release()
19