-
Notifications
You must be signed in to change notification settings - Fork 2
/
auto_fetcher.py
38 lines (30 loc) · 911 Bytes
/
auto_fetcher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
__all__ = [
'AutoFetcher',
]
from Manifest import threading, time
class AutoFetcher:
def __init__(self, interval, change_callback=None):
self.__thread = threading.Thread(target=self.__UpdateForever)
self.__interval = max(0, float(interval))
self.__thread.daemon = True
self.__thread.start()
self.__lock = threading.Lock()
self.__change_callback = change_callback
def _LockGuard(self):
return self.__lock
def __UpdateForever(self):
while True:
time.sleep(self.__interval)
self._Update()
def _Update(self):
raise NotImplementedError()
def _CallChangeCallback(self):
if self.__change_callback:
try:
self.__change_callback(self)
except Exception, e:
print ('Error calling %s: %s'
% (self.__change_callback, e))
self.__change_callback = None
def IsAlive(self):
return self.__thread.isAlive()