While having problems with python timers I found that when bottle.py is run with "reloader = True", all timer functions run twice in rapid succession.
I have tried this with several different methods of invoking the timers and the result is the same in all instances (double firing).
The sample code:
#!/usr/bin/env python
from threading import Timer
from bottle import *
# Short timer
def short_time():
t = Timer(1, short_time)
t.daemon = True
t.start()
print "Short Time..."
# Long timer
def long_time():
t = Timer(5, long_time)
t.daemon = True
t.start()
print "Long Time..."
# The App
app = Bottle()
@app.route('/status')
def default():
return "OK"
#Run the app -----
if __name__ == '__main__':
# Start the short timer.
short_time()
# Start the long timer.
long_time()
# Run the app
# This interferes with the timers
run(app, host='0.0.0.0', port=8002, reloader=True)
#This one works as expected
#run(app, host='0.0.0.0', port=8002) #This works fine
The output with reloader enabled:
Short Time...
Short Time...
Short Time...
Short Time...
Short Time...
Short Time...
Short Time...
Short Time...
Long Time...
Short Time...
Long Time...
Short Time...
Short Time...
Short Time...
The expected output (without reloader):
Short Time...
Short Time...
Short Time...
Short Time...
Long Time...
Short Time...
Short Time...
Short Time...
Short Time...
Short Time...
Long Time...
Short Time...
Short Time...
Any ideas on how to use reloader, but prevent the timer problem?