Skip to content

Commit 233a076

Browse files
committed
fix: distributing tests with pytest -n auto
1 parent bb1078d commit 233a076

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

pydra/engine/run_pickled_function.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import sys
44

55
def run_pickled():
6-
with open('/pydra/pydra/engine/my_function.pkl', 'rb') as file:
6+
file_path = sys.argv[1]
7+
with open(file_path, 'rb') as file:
78
loaded_function = pickle.load(file)
89

910
result = loaded_function(rerun=False)

pydra/engine/run_pickled_function_2.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
import sys
44

55
def run_pickled():
6-
with open('/pydra/pydra/engine/my_function.pkl', 'rb') as file:
6+
file_path_1 = sys.argv[1]
7+
file_path_2 = sys.argv[2]
8+
file_path_3 = sys.argv[3]
9+
with open(file_path_1, 'rb') as file:
710
loaded_function = pickle.load(file)
8-
with open('/pydra/pydra/engine/taskmain.pkl', 'rb') as file:
11+
with open(file_path_2, 'rb') as file:
912
taskmain = pickle.load(file)
10-
with open('/pydra/pydra/engine/ind.pkl', 'rb') as file:
13+
with open(file_path_3, 'rb') as file:
1114
ind = pickle.load(file)
1215

1316
result = loaded_function(taskmain, ind, rerun=False)

pydra/engine/workers.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -923,22 +923,29 @@ def make_job(self, spec, attributes):
923923
async def exec_psij(self, runnable, rerun=False):
924924
import psij
925925
import pickle
926+
import os
926927
self.psij = psij
927928
jex = psij.JobExecutor.get_instance('slurm')
928-
929+
929930
if isinstance(runnable, TaskBase):
930-
with open('/pydra/pydra/engine/my_function.pkl', 'wb') as file:
931+
cache_dir = runnable.cache_dir
932+
file_path = os.path.join(cache_dir, 'my_function.pkl')
933+
with open(file_path, 'wb') as file:
931934
pickle.dump(runnable._run, file)
932-
spec = self.make_spec("python3.9", ["/pydra/pydra/engine/run_pickled_function.py"])
935+
spec = self.make_spec("python3.9", ["/pydra/pydra/engine/run_pickled_function.py", file_path])
933936
else: # it could be tuple that includes pickle files with tasks and inputs
937+
cache_dir = runnable[-1].cache_dir
938+
file_path_1 = os.path.join(cache_dir, 'my_function.pkl')
939+
file_path_2 = os.path.join(cache_dir, 'taskmain.pkl')
940+
file_path_3 = os.path.join(cache_dir, 'ind.pkl')
934941
ind, task_main_pkl, task_orig = runnable
935-
with open('/pydra/pydra/engine/my_function.pkl', 'wb') as file:
942+
with open(file_path_1, 'wb') as file:
936943
pickle.dump(load_and_run, file)
937-
with open('/pydra/pydra/engine/taskmain.pkl', 'wb') as file:
944+
with open(file_path_2, 'wb') as file:
938945
pickle.dump(task_main_pkl, file)
939-
with open('/pydra/pydra/engine/ind.pkl', 'wb') as file:
946+
with open(file_path_3, 'wb') as file:
940947
pickle.dump(ind, file)
941-
spec = self.make_spec("python3.9", ["/pydra/pydra/engine/run_pickled_function_2.py"])
948+
spec = self.make_spec("python3.9", ["/pydra/pydra/engine/run_pickled_function_2.py", file_path_1, file_path_2, file_path_3])
942949

943950
job = self.make_job(spec, None)
944951
jex.submit(job)

0 commit comments

Comments
 (0)