提交 b818e5ed 编写于 作者: T TomorrowIsAnOtherDay

fix the bug of distributing files

上级 ccde3771
...@@ -269,13 +269,15 @@ class Job(object): ...@@ -269,13 +269,15 @@ class Job(object):
# create directory (i.e. ./rom_files/) # create directory (i.e. ./rom_files/)
if '/' in file: if '/' in file:
try: try:
os.makedirs(os.path.join(*file.rsplit('/')[:-1])) sep = os.sep
recursive_dirs = os.path.join(*(file.split(sep)[:-1]))
recursive_dirs = os.path.join(envdir, recursive_dirs)
os.makedirs(recursive_dirs)
except OSError as e: except OSError as e:
pass pass
file = os.path.join(envdir, file) 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')
reply_socket.send_multipart([remote_constants.NORMAL_TAG]) reply_socket.send_multipart([remote_constants.NORMAL_TAG])
return envdir return envdir
else: else:
...@@ -358,7 +360,7 @@ class Job(object): ...@@ -358,7 +360,7 @@ class Job(object):
self.single_task(obj, reply_socket, job_address) self.single_task(obj, reply_socket, job_address)
except Exception as e: except Exception as e:
logger.error( logger.error(
"Error occurs when running a single task. We will reset this job. Reason:{}" "Error occurs when running a single task. We will reset this job. \nReason:{}"
.format(e)) .format(e))
traceback_str = str(traceback.format_exc()) traceback_str = str(traceback.format_exc())
logger.error("traceback:\n{}".format(traceback_str)) logger.error("traceback:\n{}".format(traceback_str))
......
...@@ -22,10 +22,11 @@ import threading ...@@ -22,10 +22,11 @@ import threading
c = 10 c = 10
port = 3002 port = 3002
master = Master(port=port) if __name__ == '__main__':
th = threading.Thread(target=master.run) master = Master(port=port)
th.setDaemon(True) th = threading.Thread(target=master.run)
th.start() th.setDaemon(True)
th.start()
time.sleep(5) time.sleep(5)
cluster_addr = 'localhost:{}'.format(port) cluster_addr = 'localhost:{}'.format(port)
parl.connect(cluster_addr) parl.connect(cluster_addr)
......
...@@ -17,12 +17,10 @@ import parl ...@@ -17,12 +17,10 @@ import parl
from parl.remote.master import Master from parl.remote.master import Master
from parl.remote.worker import Worker from parl.remote.worker import Worker
from parl.remote.client import disconnect from parl.remote.client import disconnect
import os
import time import time
import threading import threading
import sys import sys
import numpy as np import numpy as np
import json import json
...@@ -65,7 +63,8 @@ class TestConfigfile(unittest.TestCase): ...@@ -65,7 +63,8 @@ class TestConfigfile(unittest.TestCase):
parl.connect('localhost:1335', ['random.npy', 'config.json']) parl.connect('localhost:1335', ['random.npy', 'config.json'])
actor = Actor('random.npy', 'config.json') actor = Actor('random.npy', 'config.json')
time.sleep(5) time.sleep(5)
os.remove('./random.npy')
os.remove('./config.json')
remote_sum = actor.random_sum() remote_sum = actor.random_sum()
self.assertEqual(remote_sum, random_sum) self.assertEqual(remote_sum, random_sum)
time.sleep(10) time.sleep(10)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册