| 74 | import threading |
| 75 | |
| 76 | class 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 | |
| 90 | print("Example 3") |
no outgoing calls