-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathextension_eim_trigger.py
executable file
·39 lines (34 loc) · 1.25 KB
/
extension_eim_trigger.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
import time
import importlib, sys
from codelab_adapter import settings
from codelab_adapter.core_extension import Extension
import zmq
class EimTriggerExtension(Extension):
def __init__(self):
super().__init__()
self.EXTENSION_ID = "eim"
def run(self):
module_name = "eim_trigger"
try:
importlib.import_module(module_name)
except Exception as e:
self.pub_notification(f'{e}', type="ERROR")
return
module = sys.modules[module_name]
importlib.reload(module)
while self._running:
# monitor返回值被pub
# rate = 10
# time.sleep(1/rate) # 默认频率是每秒运行十次这个函数
try:
response = sys.modules[
module_name].trigger() # 休眠1s,阻塞,stop会报错, 等待退出,todo 非守护进程
if response:
message = {"payload": {"content": response}}
self.publish(message)
except zmq.error.ZMQError as e:
self.logger.error(f'{e}')
except Exception as e:
self.logger.error(f'{e}')
# self.pub_notification(f'{e}')
export = EimTriggerExtension