MCPcopy Create free account
hub / github.com/bslatkin/effectivepython / ReusableTimer

Class ReusableTimer

example_code/item_109.py:76–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74import threading
75
76class ReusableTimer:
77 def __init__(self):
78 self.timer = None
79
80 def countdown(self, duration, callback):
81 self.end()
82 self.timer = threading.Timer(duration, callback)
83 self.timer.start()
84
85 def end(self):
86 if self.timer:
87 self.timer.cancel()
88
89
90print("Example 3")

Callers 5

item_109.pyFile · 0.85
test_countdownMethod · 0.85
test_endMethod · 0.85
setUpMethod · 0.85
setUpMethod · 0.85

Calls

no outgoing calls

Tested by 2

test_countdownMethod · 0.68
test_endMethod · 0.68