Skip to content
Permalink
Browse files
feat: LockException (#1276)
* add LockException

* add tests

* try older mamba

Co-authored-by: Johannes Köster <johannes.koester@tu-dortmund.de>
  • Loading branch information
Maarten-vd-Sande and johanneskoester committed May 10, 2022
1 parent bf2d1b9 commit f5e6fa68a68640ed39df86c256d676f2e4efddfc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
@@ -530,3 +530,17 @@ def __init__(self, rule, targetfile):

class CacheMissException(Exception):
pass


class LockException(WorkflowError):
def __init__(self):
super().__init__(
"Error: Directory cannot be locked. Please make "
"sure that no other Snakemake process is trying to create "
"the same files in the following directory:\n{}\n"
"If you are sure that no other "
"instances of snakemake are running on this directory, "
"the remaining lock was likely caused by a kill signal or "
"a power loss. It can be removed with "
"the --unlock argument.".format(os.getcwd())
)
@@ -15,6 +15,7 @@
from itertools import filterfalse, count
from pathlib import Path

import snakemake.exceptions
from snakemake.logging import logger
from snakemake.jobs import jobfiles
from snakemake.utils import listfiles
@@ -167,7 +168,7 @@ def lock_warn_only(self):

def lock(self):
if self.locked:
raise IOError("Another snakemake process " "has locked this directory.")
raise snakemake.exceptions.LockException()
self._lock(self.all_inputfiles(), "input")
self._lock(self.all_outputfiles(), "output")

@@ -798,20 +798,7 @@ def files(items):
dag.update_checkpoint_dependencies()
dag.check_dynamic()

try:
self.persistence.lock()
except IOError:
logger.error(
"Error: Directory cannot be locked. Please make "
"sure that no other Snakemake process is trying to create "
"the same files in the following directory:\n{}\n"
"If you are sure that no other "
"instances of snakemake are running on this directory, "
"the remaining lock was likely caused by a kill signal or "
"a power loss. It can be removed with "
"the --unlock argument.".format(os.getcwd())
)
return False
self.persistence.lock()

if cleanup_shadow:
self.persistence.cleanup_shadow()
@@ -80,3 +80,17 @@ def test_dicts_in_config():
"test": {"this_dict": "shoult_not_either"},
},
)

def test_lockexception():
from snakemake.persistence import Persistence
from snakemake.exceptions import LockException

persistence = Persistence()
persistence.all_inputfiles = lambda: ["A.txt"]
persistence.all_outputfiles = lambda: ["B.txt"]
persistence.lock()
try:
persistence.lock()
except LockException as e:
return True
assert False

0 comments on commit f5e6fa6

Please sign in to comment.