Skip to content

Commit

Permalink
Merge pull request #564 from opensafely-core/fix-windows-again
Browse files Browse the repository at this point in the history
fix: more careful tempfile handling
  • Loading branch information
bloodearnest authored Jan 27, 2023
2 parents 0cda301 + 63b6458 commit 4211364
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Binary file added jobrunner/executors/.volumes.py.swp
Binary file not shown.
13 changes: 10 additions & 3 deletions jobrunner/executors/volumes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import importlib
import logging
import os
import shutil
import tempfile
import time
Expand Down Expand Up @@ -49,11 +50,17 @@ def delete_volume(job):
docker.delete_volume(docker_volume_name(job))

def write_timestamp(job, path, timeout=None):
with tempfile.NamedTemporaryFile("w") as f:
f.write(str(time.time_ns()))
f.flush()
try:
f = tempfile.NamedTemporaryFile(delete=False)
f.close()
p = Path(f.name)
p.write_text(str(time.time_ns()))
docker.copy_to_volume(docker_volume_name(job), p, path, timeout)
finally:
try:
os.remove(f.name)
except Exception:
pass

def read_timestamp(job, path, timeout=None):
return docker.read_timestamp(docker_volume_name(job), path, timeout)
Expand Down

0 comments on commit 4211364

Please sign in to comment.