Prompt that the file path cannot be found when using PARL
Created by: YaoCharlie
Using PARL for distributed computing,The directory structure is as follows: Document Pro |Pacakage | | Moudle.py |___ main.py We define class in Module.py in Pacakage,then use @parl.remote_class. Connect master in main.py and start the program,then Prompt the following error: ... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ... [Errno 2] No such file or directory: 'Module.py' traceback: Traceback (most recent call last): File "/home/wangderi/anaconda3/envs/parl/lib/python3.6/site-packages/parl/remote/job.py", line 316, in wait_for_connection cls = load_remote_class(file_name, class_name, end_of_file) File "/home/wangderi/anaconda3/envs/parl/lib/python3.6/site-packages/parl/remote/utils.py", line 60, in load_remote_class with open(file_name + ".py") as t_file: FileNotFoundError: [Errno 2] No such file or directory: 'Module.py' ... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ... I switched to an absolute path but still reported the same error. ... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...
The code as followed: ... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...
Moudle.py: ... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...
import parl
import threading
import time, os
@parl.remote_class
class parlTest():
def run(self):
ans = 0
for i in range(100000000):
ans += i
print(ans)
def long_time_task(self, name):
print('Run task %s (%s)...' % (name, os.getpid()))
threads = []
for i in range(1):
t = threading.Thread(target=self.run, name='LoopThread%d'%(i))
t.start()
threads.append(t)
for t in threads:
t.join()
... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...
main.py ... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...
import time, os
import threading
from multiprocessing import Pool
from absl import app
from absl import flags
from absl import logging
from yours.Module import parlTest
import parl
FlAGS = flags.FLAGS
flags.DEFINE_integer('mode', 0, 'Runing mode')
flags.DEFINE_integer('task_num', 4, 'number of task')
class Test():
def run(self):
ans = 0
for i in range(100000000):
ans += i
def long_time_task(self, name):
print('Run task %s (%s)...' % (name, os.getpid()))
threads = []
for i in range(1):
t = threading.Thread(target=self.run, name='LoopThread%d'%(i))
t.start()
threads.append(t)
for t in threads:
t.join()
def main(argv):
del argv
if FlAGS.mode == 0:
print("Enable Multiprocessing with PARL ... ...")
parl.connect("10.1.14.249:36000")
test = parlTest()
print('Parent process %s.' % os.getpid())
start = time.clock()
p = Pool(FlAGS.task_num)
for i in range(FlAGS.task_num):
p.apply_async(test.long_time_task, args=(i,))
print('Waiting for all subprocesses done...')
p.close()
p.join()
end = time.clock()
print('All subprocesses done.')
print("Total cost time %f seconds"%(end - start))
elif FlAGS.mode == 1:
print("Enable Multiprocessing without PARL ... ...")
test = Test()
print('Parent process %s.' % os.getpid())
start = time.clock()
p = Pool(FlAGS.task_num)
for i in range(FlAGS.task_num):
p.apply_async(test.long_time_task, args=(i,))
print('Waiting for all subprocesses done...')
p.close()
p.join()
end = time.clock()
print('All subprocesses done.')
print("Total cost time %f seconds"%(end - start))
elif FlAGS.mode == 2:
print("Enable Multithreading with PARL ... ...")
parl.connect("10.1.14.249:36000")
test = parlTest()
start = time.clock()
threads = []
for _ in range(FlAGS.task_num):
th = threading.Thread(target=test.run)
th.start()
threads.append(th)
end = time.clock()
for th in threads:
th.join()
print("Total cost time %f seconds"%(end - start))
elif FlAGS.mode == 3:
print("Enable Multithreading without PARL ... ...")
test = Test()
start = time.clock()
threads = []
for _ in range(FlAGS.task_num):
th = threading.Thread(target=test.run)
th.start()
threads.append(th)
end = time.clock()
for th in threads:
th.join()
print("Total cost time %f seconds"%(end - start))
elif FlAGS.mode == 4:
print("Enable Serial calculations with PARL ... ...")
parl.connect("10.1.14.249:36000")
test = parlTest()
start = time.clock()
for _ in range(FlAGS.task_num):
test.run()
end = time.clock()
print("Total cost time %f seconds"%(end - start))
elif FlAGS.mode == 5:
print("Enable Serial calculations without PARL ... ...")
test = Test()
start = time.clock()
for _ in range(FlAGS.task_num):
test.run()
end = time.clock()
print("Total cost time %f seconds"%(end - start))
else:
print("Does not have such mode!!!")
if __name__=='__main__':
app.run(main)