-
Notifications
You must be signed in to change notification settings - Fork 9
/
detect_code_change.py
60 lines (38 loc) · 1.29 KB
/
detect_code_change.py
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
"""Illustrate saving checkpoints and resuming from the last modified function.
Run this code first to generate the call graph and breakpoints. Then modify one
of the functions step0, step1, or step2. When you rerun the code, it will
resume from whichever function you modified.
"""
import logging
import function_checkpointing as ckpt
def step0():
print(">step 1")
def step1():
print(">step 2")
def step2():
print(">step 3")
def processing():
print("starting processing")
if not ckpt.save_checkpoint_and_call_log("step0"):
print("Resuming before step0")
step0()
if not ckpt.save_checkpoint_and_call_log("step1"):
print("Resuming before step1")
step1()
if not ckpt.save_checkpoint_and_call_log("step2"):
print("Resuming before step2")
step2()
print("done")
def main():
logging.basicConfig()
logging.getLogger("function_checkpointing").setLevel(logging.DEBUG)
logging.getLogger("function_checkpointing.save_restore").setLevel(logging.DEBUG)
logging.root.setLevel(logging.DEBUG)
try:
ckpt.resume_from_last_unchanged_checkpoint()
except ckpt.CheckpointNotFound:
print("Starting from scratch")
ckpt.start_call_tracing([__file__])
processing()
if __name__ == "__main__":
main()