Skip to content

Commit

Permalink
fix: Fix race condition when creating lock directory (#2225)
Browse files Browse the repository at this point in the history
### Description

This PR makes two changes:

1. when `--nolock` is set, it will avoid creating a lock directory
2. when multiple instances of snakemake are running there is a race
condition on the `os.mkdir` call. Switching to `os.makedirs` and setting
`exist_ok=True` will simply avoid raising an exception in this case.

### QC

* [x] The PR contains a test case for the changes or the changes are
already covered by an existing test case.
* [x] The documentation (`docs/`) is updated to reflect the changes or
this is not necessary (e.g. if the change does neither modify the
language nor the behavior or functionalities of Snakemake).

---------

Co-authored-by: Johannes Köster <johannes.koester@tu-dortmund.de>
  • Loading branch information
sirno and johanneskoester committed Apr 28, 2023
1 parent da246d2 commit 66ea4d1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions snakemake/persistence.py
Expand Up @@ -45,12 +45,12 @@ def __init__(
self._serialize_param = self._serialize_param_builtin

self._max_len = None

self.path = os.path.abspath(".snakemake")
if not os.path.exists(self.path):
os.mkdir(self.path)
os.makedirs(self.path, exist_ok=True)

self._lockdir = os.path.join(self.path, "locks")
if not os.path.exists(self._lockdir):
os.mkdir(self._lockdir)
os.makedirs(self._lockdir, exist_ok=True)

self.dag = dag
self._lockfile = dict()
Expand Down

0 comments on commit 66ea4d1

Please sign in to comment.