提交 ccde3771 编写于 作者: T TomorrowIsAnOtherDay

fix workspace bug

上级 b56914ac
...@@ -272,6 +272,7 @@ class Job(object): ...@@ -272,6 +272,7 @@ class Job(object):
os.makedirs(os.path.join(*file.rsplit('/')[:-1])) os.makedirs(os.path.join(*file.rsplit('/')[:-1]))
except OSError as e: except OSError as e:
pass pass
file = os.path.join(envdir, file)
with open(file, 'wb') as f: with open(file, 'wb') as f:
f.write(content) f.write(content)
logger.info('[job] reply') logger.info('[job] reply')
...@@ -350,6 +351,7 @@ class Job(object): ...@@ -350,6 +351,7 @@ class Job(object):
# receive source code from the actor and append them to the environment variables. # receive source code from the actor and append them to the environment variables.
envdir = self.wait_for_files(reply_socket, job_address) envdir = self.wait_for_files(reply_socket, job_address)
sys.path.append(envdir) sys.path.append(envdir)
os.chdir(envdir)
obj = self.wait_for_connection(reply_socket) obj = self.wait_for_connection(reply_socket)
assert obj is not None assert obj is not None
......
...@@ -44,7 +44,7 @@ def simplify_code(code, end_of_file): ...@@ -44,7 +44,7 @@ def simplify_code(code, end_of_file):
def load_remote_class(file_name, class_name, end_of_file): def load_remote_class(file_name, class_name, end_of_file):
""" """
load a class given its file_name and class_name. load a class given its file_name and class_name.
Args: Args:
...@@ -55,13 +55,14 @@ def load_remote_class(file_name, class_name, end_of_file): ...@@ -55,13 +55,14 @@ def load_remote_class(file_name, class_name, end_of_file):
Return: Return:
cls: the class to load 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 = t_file.readlines()
code = simplify_code(code) code = simplify_code(code, end_of_file)
tmp_file_name = 'xparl_' + file_name module_name = 'xparl_' + file_name
tmp_file_name = 'xparl_' + file_name + '.py'
with open(tmp_file_name, 'w') as t_file: with open(tmp_file_name, 'w') as t_file:
for line in code: for line in code:
t_file.write(line) t_file.write(line)
mod = __import__(tmp_file_name) mod = __import__(module_name)
cls = getattr(mod, class_name)._original cls = getattr(mod, class_name)
return cls return cls
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册