Skip to content

Commit

Permalink
Move all dumps to cloudpickle (#30)
Browse files Browse the repository at this point in the history
* Move all dumps to cloudpickle

Co-authored-by: Jeremy Rapin <[email protected]>
  • Loading branch information
jrapin and jrapin authored Oct 22, 2020
1 parent 218ffa4 commit fc70208
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions submitit/core/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ def process_job(folder: Union[Path, str]) -> None:
env._handle_signals(paths, delayed)
result = delayed.result()
with utils.temporary_save_path(paths.result_pickle) as tmppath: # save somewhere else, and move
utils.pickle_dump(("success", result), tmppath)
utils.cloudpickle_dump(("success", result), tmppath)
logger.info("Job completed successfully")
except Exception as error: # TODO: check pickle methods for capturing traceback; pickling and raising
try:
with utils.temporary_save_path(paths.result_pickle) as tmppath:
utils.pickle_dump(("error", traceback.format_exc()), tmppath)
utils.cloudpickle_dump(("error", traceback.format_exc()), tmppath)
except Exception as dumperror:
logger.error(f"Could not dump error:\n{error}\n\nbecause of {dumperror}")
logger.error("Submitted job triggered an exception")
Expand Down
4 changes: 2 additions & 2 deletions submitit/core/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ def test_fake_job(tmp_path: Path) -> None:
f.write("blublu")
assert job.stderr() == "blublu"
# result
utils.pickle_dump(("success", 12), job.paths.result_pickle)
utils.cloudpickle_dump(("success", 12), job.paths.result_pickle)
assert job.result() == 12
# exception
assert job.exception() is None
utils.pickle_dump(("error", "blublu"), job.paths.result_pickle)
utils.cloudpickle_dump(("error", "blublu"), job.paths.result_pickle)
assert isinstance(job.exception(), Exception)
with pytest.raises(core.utils.FailedJobError):
job.result()
Expand Down
5 changes: 0 additions & 5 deletions submitit/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,6 @@ def pickle_load(filename: Union[str, Path]) -> Any:
return pickle.load(ifile)


def pickle_dump(obj: Any, filename: Union[str, Path]) -> None:
with open(filename, "wb") as ofile:
pickle.dump(obj, ofile, pickle.HIGHEST_PROTOCOL)


def cloudpickle_dump(obj: Any, filename: Union[str, Path]) -> None:
with open(filename, "wb") as ofile:
cloudpickle.dump(obj, ofile, pickle.HIGHEST_PROTOCOL)
Expand Down
9 changes: 9 additions & 0 deletions submitit/local/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ def failing_job() -> None:
assert "Failed on purpose" in traceback


def test_pickle_output_from_main(tmp_path: Path) -> None:
class MyClass:
pass

executor = local.LocalExecutor(tmp_path)
job = executor.submit(MyClass.__call__)
assert isinstance(job.result(), MyClass)


def test_get_first_task_error(tmp_path: Path) -> None:
def flaky() -> None:
job_env = job_environment.JobEnvironment()
Expand Down

0 comments on commit fc70208

Please sign in to comment.