In file ai2_kit/domain.py
def fun(ctx):
def in_add(a, b):
print (a+b)
ctx.executor.run_python_fn(in_add)(1, 2) # this pass
ctx.executor.run_python_fn(out_add)(1, 2) # this failed, the error is: ModuleNotFoundError: No module named 'ai2_kit'
def out_add(a, b):
print(a+b)
the method run_python_fn
is defined in ai2_kit/executor.py , the basic idea is use python -c
to execute a python script on remote machine.
def run_python_script(self, script: str):
return self.connector.run('python -c {}'.format(shlex.quote(script)))
def run_python_fn(self, fn: T, python_cmd=None) -> T:
def remote_fn(*args, **kwargs):
dumped_fn = base64.b64encode(cloudpickle.dumps(lambda: fn(*args, **kwargs), protocol=pickle.DEFAULT_PROTOCOL))
script = '''import base64,pickle; pickle.loads(base64.b64decode({}))()'''.format(repr(dumped_fn))
self.run_python_script(script=script, python_cmd=python_cmd)
I have no idea why it will import ai2_kit
when use a function outside of current function, the method out_add
doesn't have any external dependencies. Is there any method to workaround this problem? Thank you! Both local and remote python is v3.9.