-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreload.py
82 lines (59 loc) · 1.81 KB
/
reload.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
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
# -*- coding: utf-8 -*-
import sys
import os
from imp import reload
from .libs import log, paths, storage
dirname = os.path.split(os.path.dirname(__file__))[1]
all_modules = [
"libs.log",
"libs.paths",
"libs.storage",
"package_control_setting",
"s6_setting",
"setting_sync",
]
def reload_module():
for module in all_modules:
name = "%s.%s" % (dirname, module)
reload(sys.modules[name])
# stop_thread(main_thread)
def plugin_loaded():
log.debug("---------- plugin_loaded ----------")
reload_module()
# [comment by Floyda] start_thread()
def plugin_unloaded():
log.debug("---------- plugin_unloaded ----------")
# [comment by Floyda] stop_thread(main_thread)
import threading
import time
import inspect
import ctypes
def _async_raise(tid, exctype):
"""raises the exception, performs cleanup if needed"""
tid = ctypes.c_long(tid)
if not inspect.isclass(exctype):
exctype = type(exctype)
pyobj = ctypes.py_object(exctype)
res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, pyobj)
if res == 0:
raise ValueError("invalid thread id")
elif res != 1:
# """if it returns a number greater than one, you're in trouble,
# and you should call it again with exc=NULL to revert the effect"""
ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, None)
raise SystemError("PyThreadState_SetAsyncExc failed")
def start_thread():
log.debug("start thread")
# main_thread.start()
def stop_thread(thread):
try:
_async_raise(thread.ident, SystemExit)
log.debug("stop thread")
except:
log.debug("stop thread failed")
TICK_TIME = 1
class Tick(threading.Thread):
def run(self):
while True:
time.sleep(TICK_TIME)
# [comment by Floyda] main_thread = Tick()