Skip to content

Commit

Permalink
fix: fix premature deletion of temp files in combination with checkpo…
Browse files Browse the repository at this point in the history
…ints (#2737)

fixes #2732

### QC
<!-- Make sure that you can tick the boxes below. -->

* [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).
  • Loading branch information
johanneskoester committed Mar 7, 2024
1 parent e0a6be4 commit b22ba5f
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 7 deletions.
9 changes: 7 additions & 2 deletions snakemake/dag.py
Expand Up @@ -1845,8 +1845,13 @@ async def finish(self, job, update_checkpoint_dependencies=True):
self.create_conda_envs()
potential_new_ready_jobs = True

for job in jobs:
await self.handle_temp(job)
if not any(self.checkpoint_jobs):
# While there are still checkpoint jobs, we cannot safely delete
# temp files.
# TODO: we maybe could be more accurate and determine whether there is a
# checkpoint that depends on the temp file.
for job in jobs:
await self.handle_temp(job)

return potential_new_ready_jobs

Expand Down
38 changes: 38 additions & 0 deletions tests/test_github_issue2732/Snakefile
@@ -0,0 +1,38 @@
rule a:
output:
temp("{name}.txt"),
shell:
"touch {output}"

rule a1:
input:
"{name}.txt",
output:
temp("{name}.a1.out"),
shell:
"touch {output}"

rule b1:
input:
"A.txt",
output:
temp("A.b1.out"),
shell:
"touch {output}"

checkpoint b2:
input:
"A.b1.out"
output:
"A.b2.out"
shell:
"echo A > {output}"

def in_func1(w):
file = checkpoints.b2.get().output[0]
return open(file, "r").read().strip()

rule all:
input:
lambda w: expand(rules.a1.output, name=in_func1(w)),
default_target: True
Empty file.
1 change: 1 addition & 0 deletions tests/test_github_issue2732/expected-results/A.b2.out
@@ -0,0 +1 @@
A
15 changes: 10 additions & 5 deletions tests/tests.py
Expand Up @@ -2014,32 +2014,37 @@ def test_issue2685():
run(dpath("test_issue2685"))


@skip_on_windows
@skip_on_windows # OS agnostic
def test_set_resources_complex():
run(
dpath("test05"),
shellcmd="snakemake -c1 --set-resources \"compute1:slurm_extra='--nice=10'\"",
)


@skip_on_windows
@skip_on_windows # OS agnostic
def test_set_resources_human_readable():
run(
dpath("test05"),
shellcmd="snakemake -c1 --set-resources \"compute1:runtime='50h'\"",
)


@skip_on_windows
@skip_on_windows # OS agnostic
def test_call_inner():
run(dpath("test_inner_call"))


@skip_on_windows
@skip_on_windows # OS agnostic
def test_list_input_changes():
run(dpath("test01"), shellcmd="snakemake --list-input-changes", check_results=False)


@skip_on_windows
@skip_on_windows # OS agnostic
def test_summary():
run(dpath("test01"), shellcmd="snakemake --summary", check_results=False)


@skip_on_windows # OS agnostic
def test_github_issue2732():
run(dpath("test_github_issue2732"))

0 comments on commit b22ba5f

Please sign in to comment.