Package conduit :: Package utils :: Module Thread
[hide private]

Source Code for Module conduit.utils.Thread

 1  import time 
 2  import threading 
 3  import conduit 
 4   
5 -class PauseCancelThread(threading.Thread):
6 SLEEP_TIME = 20 7 SLEEP = 0.1
8 - def __init__(self):
9 threading.Thread.__init__(self) 10 self._cancelled = False
11
12 - def run(self):
13 raise NotImplementedError
14
15 - def pause(self):
16 i = 0 17 while ( i < (self.SLEEP_TIME/self.SLEEP) ) and ( self.is_cancelled() == False ): 18 time.sleep(self.SLEEP) 19 i += 1
20
21 - def is_cancelled(self):
22 return conduit.GLOBALS.cancelled or self._cancelled
23
24 - def cancel(self):
25 self._cancelled = True
26