File: vine_python_unlink_when_done.py

package info (click to toggle)
cctools 1%3A7.14.5-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 36,956 kB
  • sloc: ansic: 114,614; python: 29,532; cpp: 20,313; sh: 13,675; perl: 4,056; xml: 3,688; makefile: 1,436
file content (62 lines) | stat: -rw-r--r-- 1,285 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#! /usr/bin/env python

import ndcctools.taskvine as vine
import os.path as path

filename = "hello.txt"


def create_file():
    with open(filename, "w") as f:
        f.write("hello")


m = vine.DaskVine(port=[9123, 9129])

print("testing without submitting task")
create_file()
assert path.exists(filename)
f = m.declare_file("hello.txt", unlink_when_done=True)
m.remove_file(f)
assert not path.exists(filename)


class FakeTask(vine.PythonTask):
    def __init__(self, filename):
        super().__init__(lambda x: x)
        self._filename = filename
        self._cleanup = None

    def submit_finalize(self):
        self._input = m.declare_file(self._filename, unlink_when_done=True)
        self.add_input(self._input, "input")
        super().submit_finalize()

    def __del__(self):
        self._manager.remove_file(self._input)
        super().__del__()


print("test unlink_when_done deleting task")
create_file()
assert path.exists(filename)

o = m.declare_temp()

m.log_debug_app("declaring task")
t = FakeTask(filename)

t.add_output(o, "output")

id = m.submit(t)
m.cancel_by_task_id(id)

t = m.wait(5)

assert path.exists(filename)
t = None
m.remove_file(o)
m.log_debug_app(f"was hello.txt deleted? {not path.exists(filename)}")

assert not path.exists(filename)