-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathgsq.py
More file actions
86 lines (70 loc) · 1.74 KB
/
gsq.py
File metadata and controls
86 lines (70 loc) · 1.74 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import gs
import sublime
import threading
DOMAIN = 'GsQ'
class Launcher(threading.Thread):
def __init__(self, domain, f):
threading.Thread.__init__(self)
self.daemon = True
self.domain = domain
self.f = f
def run(self):
try:
self.f()
except Exception:
gs.notice(self.domain, gs.traceback())
class Runner(threading.Thread):
def __init__(self, domain, f, msg='', set_status=False):
threading.Thread.__init__(self)
self.daemon = True
self.domain = domain
self.f = f
self.msg = msg
self.set_status = set_status
def run(self):
tid = gs.begin(self.domain, self.msg, self.set_status)
try:
self.f()
except Exception:
gs.notice(self.domain, gs.traceback())
finally:
gs.end(tid)
class GsQ(threading.Thread):
def __init__(self, domain):
threading.Thread.__init__(self)
self.daemon = True
self.q = gs.queue.Queue()
self.domain = domain
def run(self):
while True:
try:
f, msg, set_status = self.q.get()
tid = gs.begin(self.domain, msg, set_status)
try:
f()
except Exception:
gs.notice(self.domain, gs.traceback())
except:
pass
gs.end(tid)
def dispatch(self, f, msg, set_status=False):
try:
self.q.put((f, msg, set_status))
except Exception:
gs.notice(self.domain, traceback())
try:
m
except:
m = {}
def dispatch(domain, f, msg='', set_status=False):
global m
q = m.get(domain, None)
if not (q and q.is_alive()):
q = GsQ(domain)
q.start()
m[domain] = q
q.dispatch(f, msg, set_status)
def do(domain, f, msg='', set_status=False):
Runner(domain, f, msg, set_status).start()
def launch(domain, f):
Launcher(domain, f).start()