forked from DisposaBoy/GoSublime
/
gsq.py
49 lines (39 loc) · 811 Bytes
/
gsq.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
45
46
47
48
49
import gscommon as gs
import threading, Queue, traceback
import sublime
DOMAIN = 'GsQ'
class GsQ(threading.Thread):
def __init__(self, domain):
threading.Thread.__init__(self)
self.daemon = True
self.q = Queue.Queue()
self.domain = domain
def run(self):
while True:
try:
f, msg = self.q.get()
tid = gs.begin(self.domain, msg, False)
try:
f()
except Exception:
gs.notice(self.domain, traceback.format_exc())
except:
pass
gs.end(tid)
def dispatch(self, f, msg):
try:
self.q.put((f, msg))
except Exception:
gs.notice(self.domain, traceback.format_exc())
try:
m
except:
m = {}
def dispatch(domain, f, msg=''):
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)