Skip to content

Commit

Permalink
fix lock file
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Kundert authored and Ken Kundert committed Mar 17, 2022
1 parent 763a7b2 commit a0d337d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions emborg/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ def read_config(self, name=None, path=None, queue=None):
config = queue.get_active_config()
self.configs = queue.configs
self.log_command = queue.log_command
self.requires_exclusivity = queue.requires_exclusivity

# save config name
settings["config_name"] = config
Expand Down Expand Up @@ -888,20 +889,22 @@ def __enter__(self):
self.data_dir = data_dir

# perform locking
lockfile = self.lockfile = data_dir / self.resolve(LOCK_FILE)
if self.requires_exclusivity:
lockfile = self.lockfile = data_dir / self.resolve(LOCK_FILE)

# check for existence of lockfile
if lockfile.exists():
report = True
try:
# check to see if the process is still running
lock_contents = lockfile.read_text()
pid = None
for l in lock_contents.splitlines():
name, _, value = l.partition("=")
if name.strip().lower() == "pid":
pid = int(value.strip())
assert pid > 0
os.kill(pid, 0)
os.kill(pid, 0) # does not actually kill the process
except ProcessLookupError as e:
if e.errno == errno.ESRCH:
report = False # process no longer exists
Expand Down

0 comments on commit a0d337d

Please sign in to comment.