Re-organization.
This commit is contained in:
parent
5db3ae2933
commit
5421ab7f6e
38 changed files with 0 additions and 0 deletions
34
scheduler.py
Normal file
34
scheduler.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import time
|
||||
import events
|
||||
"""
|
||||
A really simple scheduler. We can probably get a lot fancier with this
|
||||
in the future, but it'll do for now.
|
||||
|
||||
ADDING AN EVENT:
|
||||
* Add an entry to the 'schedule' dictionary.
|
||||
* Add the proper event_ function here.
|
||||
* Profit.
|
||||
"""
|
||||
|
||||
# The timer method to be triggered by the main server loop.
|
||||
def heartbeat():
|
||||
"""
|
||||
Handle one tic/heartbeat.
|
||||
"""
|
||||
tictime = time.time()
|
||||
for event in events.schedule:
|
||||
try:
|
||||
events.lastrun[event]
|
||||
except:
|
||||
events.lastrun[event] = time.time()
|
||||
|
||||
diff = tictime - events.lastrun[event]
|
||||
|
||||
if diff >= events.schedule[event]:
|
||||
event_func = getattr(events, event)
|
||||
|
||||
if callable(event_func):
|
||||
event_func()
|
||||
|
||||
# We'll get a new reading for time for accuracy.
|
||||
events.lastrun[event] = time.time()
|
||||
Loading…
Add table
Add a link
Reference in a new issue