Skip to content

Commit

Permalink
update env directly, instead of using generic startup hook code
Browse files Browse the repository at this point in the history
  • Loading branch information
albertz committed Feb 11, 2024
1 parent e111d55 commit f1e83a4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 16 deletions.
1 change: 0 additions & 1 deletion sisyphus/global_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
JOB_FINISHED_MARKER = "finished"
JOB_FINISHED_ARCHIVE = "finished.tar.gz"
JOB_INFO = "info"
JOB_STARTUP_HOOK_PY = "startup_hook.py"

# engine path
ENGINE_LOG = "log"
Expand Down
9 changes: 0 additions & 9 deletions sisyphus/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,6 @@ def _sis_setup_directory(self, force=False):
if not os.path.isdir(link_name):
os.symlink(src=os.path.abspath(str(creator._sis_path())), dst=link_name, target_is_directory=True)

if self._sis_environ_updates:
startup_hook_py_file = self._sis_path(gs.JOB_STARTUP_HOOK_PY)
with open(startup_hook_py_file, "w") as f:
f.write("import os\n\n")
f.write("os.environ.update({\n")
for k, v in self._sis_environ_updates.items():
f.write(f" {k!r}: {v!r},\n")
f.write("})\n\n")

# export the actual job
with gzip.open(self._sis_path(gs.JOB_SAVE), "w") as f:
pickle.dump(self, f)
Expand Down
11 changes: 5 additions & 6 deletions sisyphus/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,11 @@ def worker_helper(args):
if hasattr(task._job, "_sis_environment") and task._job._sis_environment:
task._job._sis_environment.modify_environment()

startup_hook_py_file = args.jobdir + os.path.sep + gs.JOB_STARTUP_HOOK_PY
if os.path.exists(startup_hook_py_file):
source = open(startup_hook_py_file).read()
co = compile(source, startup_hook_py_file, "exec")
user_ns = {"__file__": startup_hook_py_file, "__name__": startup_hook_py_file, "task": task, "job": job}
eval(co, user_ns, user_ns)
# Maybe update some env vars.
# Use getattr for compatibility with older serialized jobs.
if getattr(task._job, "_sis_environ_updates", None):
for k, v in task._job._sis_environ_updates.items():
os.environ[k] = v

try:
# run task
Expand Down

0 comments on commit f1e83a4

Please sign in to comment.