FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-tools/voidpp_tools/timer.py at master · voidpp/python-tools · GitHub
voidpp
/
python-tools
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
3
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python-tools
/
voidpp_tools
/
timer.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (40 loc) · 1.33 KB
Breadcrumbs
python-tools
/
voidpp_tools
/
timer.py
Copy path
File metadata and controls
51 lines (40 loc) · 1.33 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
from
threading
import
Thread
,
Event
import
logging
logger
=
logging
.
getLogger
(
__name__
)
class
RunnerThread
(
Thread
):
def
__init__
(
self
,
callback
):
super
(
RunnerThread
,
self
).
__init__
()
self
.
__callback
=
callback
def
run
(
self
):
try
:
self
.
__callback
()
except
:
logger
.
exception
(
"Error occured during timer callback run"
)
class
Timer
(
Thread
):
"""
Simple repeating timer.
"""
def
__init__
(
self
,
interval
,
callback
):
super
(
Timer
,
self
).
__init__
()
self
.
interval_event
=
Event
()
self
.
main_event
=
Event
()
self
.
interval
=
interval
self
.
callback
=
callback
self
.
daemon
=
True
# stop if the program exits
# start the thread (not the timer...)
super
(
Timer
,
self
).
start
()
def
run
(
self
):
while
self
.
main_event
.
wait
():
while
not
self
.
interval_event
.
wait
(
self
.
interval
):
runner
=
RunnerThread
(
self
.
callback
)
runner
.
setDaemon
(
True
)
runner
.
start
()
def
start
(
self
,
interval
=
None
):
if
interval
is
not
None
:
self
.
interval
=
interval
self
.
interval_event
.
clear
()
self
.
main_event
.
set
()
def
is_running
(
self
):
return
not
self
.
interval_event
.
is_set
()
def
stop
(
self
):
self
.
interval_event
.
set
()
Back
|
FazBrowse Home
|
New Git URL