From ccde3771b08d038210ed346849e4590dc16f62ad Mon Sep 17 00:00:00 2001 From: TomorrowIsAnOtherDay <2466956298@qq.com> Date: Tue, 9 Jun 2020 19:04:34 +0800 Subject: [PATCH] fix workspace bug --- parl/remote/job.py | 2 ++ parl/remote/utils.py | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/parl/remote/job.py b/parl/remote/job.py index f70e71f..e5c6965 100644 --- a/parl/remote/job.py +++ b/parl/remote/job.py @@ -272,6 +272,7 @@ class Job(object): os.makedirs(os.path.join(*file.rsplit('/')[:-1])) except OSError as e: pass + file = os.path.join(envdir, file) with open(file, 'wb') as f: f.write(content) logger.info('[job] reply') @@ -350,6 +351,7 @@ class Job(object): # receive source code from the actor and append them to the environment variables. envdir = self.wait_for_files(reply_socket, job_address) sys.path.append(envdir) + os.chdir(envdir) obj = self.wait_for_connection(reply_socket) assert obj is not None diff --git a/parl/remote/utils.py b/parl/remote/utils.py index a861162..b04ca25 100644 --- a/parl/remote/utils.py +++ b/parl/remote/utils.py @@ -44,7 +44,7 @@ def simplify_code(code, end_of_file): def load_remote_class(file_name, class_name, end_of_file): - """ + """ load a class given its file_name and class_name. Args: @@ -55,13 +55,14 @@ def load_remote_class(file_name, class_name, end_of_file): Return: cls: the class to load """ - with open(file_name) as t_file: + with open(file_name + '.py') as t_file: code = t_file.readlines() - code = simplify_code(code) - tmp_file_name = 'xparl_' + file_name + code = simplify_code(code, end_of_file) + module_name = 'xparl_' + file_name + tmp_file_name = 'xparl_' + file_name + '.py' with open(tmp_file_name, 'w') as t_file: for line in code: t_file.write(line) - mod = __import__(tmp_file_name) - cls = getattr(mod, class_name)._original + mod = __import__(module_name) + cls = getattr(mod, class_name) return cls -- GitLab