-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathRecurringTask.py
executable file
·72 lines (50 loc) · 1.53 KB
/
RecurringTask.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
"""
This application demonstrates doing something at a regular interval.
"""
import sys
from bacpypes.debugging import bacpypes_debugging, ModuleLogger
from bacpypes.consolelogging import ArgumentParser
from bacpypes.core import run
from bacpypes.task import RecurringTask
# some debugging
_debug = 0
_log = ModuleLogger(globals())
#
# PrairieDog
#
@bacpypes_debugging
class PrairieDog(RecurringTask):
def __init__(self, dog_number, interval):
if _debug: PrairieDog._debug("__init__ %r %r", dog_number, interval)
RecurringTask.__init__(self, interval)
# save the identity
self.dog_number = dog_number
# install it
self.install_task()
def process_task(self):
if _debug: PrairieDog._debug("process_task")
sys.stdout.write("%d woof!\n" % (self.dog_number,))
#
# __main__
#
def main():
# parse the command line arguments
parser = ArgumentParser(description=__doc__)
# add an argument for seconds per dog
parser.add_argument('seconds', metavar='N', type=int, nargs='+',
help='number of seconds for each dog',
)
# now parse the arguments
args = parser.parse_args()
if _debug: _log.debug("initialization")
if _debug: _log.debug(" - args: %r", args)
# make some dogs
for i, sec in enumerate(args.seconds):
dog = PrairieDog(i, sec * 1000)
if _debug: _log.debug(" - dog: %r", dog)
_log.debug("running")
run()
_log.debug("fini")
if __name__ == "__main__":
main()