-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythonLauncherV0.py
More file actions
33 lines (29 loc) · 955 Bytes
/
pythonLauncherV0.py
File metadata and controls
33 lines (29 loc) · 955 Bytes
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
import sys
import cbor
import zmq
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind(sys.argv[1])
module = {}
while True:
req = cbor.loads(socket.recv())
rep = {'success': True}
req['cmd']=req['cmd']#.decode("utf-8")
if req['cmd'] == 'loadCode':
try:
req['code']=req['code']#.decode("utf-8")
exec(req['code'],module)
except Exception as e:
import traceback
rep = {'success': False, 'error': traceback.format_exc()}
elif req['cmd'] == 'callFunc':
try:
req['func']=req['func']#.decode("utf-8")
func = module[req['func']]
rep['ret'] = func(*req['args'])
except Exception as e:
import traceback
rep = {'success': False, 'error': traceback.format_exc()}
else:
rep = {'success': False, 'error': f'unknown command: "{req["cmd"]}"'}
socket.send(cbor.dumps(rep))