-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathtimer.py
More file actions
40 lines (27 loc) · 721 Bytes
/
timer.py
File metadata and controls
40 lines (27 loc) · 721 Bytes
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
#!/usr/bin/python
## A Timer starts its work after a delay,
## and can be canceled at any point within that delay time period.
import threading
import time
import logging
logging.basicConfig(
level=logging.DEBUG,
format='(%(threadName)-10s) %(message)s',
)
def delayed():
logging.debug('Thread program still running')
return
def Main():
t1 = threading.Timer(3, delayed)
t1.setName('Timer 1')
t2 = threading.Timer(3, delayed)
t2.setName('Timer 2')
logging.debug('Starting thread timers')
t1.start()
t2.start()
logging.debug('We are waiting before canceling %s', t2.getName())
time.sleep(2)
logging.debug('Now canceling %s', t2.getName())
t2.cancel()
if __name__ == "__main__":
Main()