organize remotely executing functions in "cmdeploy.remote" sub package

This commit is contained in:
holger krekel
2024-08-01 19:02:41 +02:00
parent cdfce25494
commit e973bc1f41
11 changed files with 131 additions and 77 deletions

View File

@@ -0,0 +1,34 @@
import builtins
import importlib
import traceback
## Function Execution server
def _run_loop(cmd_channel):
while 1:
cmd = cmd_channel.receive()
if cmd is None:
break
cmd_channel.send(_handle_one_request(cmd))
def _handle_one_request(cmd):
pymod_path, func_name, kwargs = cmd
try:
mod = importlib.import_module(pymod_path)
func = getattr(mod, func_name)
res = func(**kwargs)
return ("finish", res)
except:
data = traceback.format_exc()
return ("error", data)
def main(channel):
# enable simple "print" logging
builtins.print = lambda x="": channel.send(("log", x))
_run_loop(channel)