-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkUtil.py
44 lines (33 loc) · 917 Bytes
/
kUtil.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
39
40
41
42
43
44
import os
import threading
import time
def oj(*args):
return os.path.join(*args)
def ls(*args):
return os.listdir(*args)
def oe(path):
return os.path.exists(path)
def kdefaultdict():
return True
class pollExec(object):
def __init__(self, ival, func, *args, **kws):
self.func = func
self.ival = ival
self.args = args
self.kws = kws
self.pauseFlag = False
self.timer = threading.Timer(interval=self.ival, function=self.f)
def start(self):
self.timer.start()
def pause(self):
self.pauseFlag = True
def restart(self):
self.pauseFlag = False
def cancel(self):
self.timer.cancel()
def f(self):
while self.pauseFlag:
time.sleep(1)
self.func(*self.args, **self.kws)
self.timer = threading.Timer(interval=self.ival, function=self.f)
self.timer.start()