MCPcopy Create free account
hub / github.com/dabeaz/python-cookbook / CountdownTask

Class CountdownTask

src/12/how_to_start_and_stop_threads/example.py:4–15  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2import time
3
4class CountdownTask:
5 def __init__(self):
6 self._running = True
7
8 def terminate(self):
9 self._running = False
10
11 def run(self, n):
12 while self._running and n > 0:
13 print("T-minus", n)
14 n -= 1
15 time.sleep(5)
16
17c = CountdownTask()
18t = Thread(target=c.run, args=(10,))

Callers 1

example.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected