mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-02-04 09:14:30 +00:00
Partial reimplementation of the web server using Tornado #3
This commit is contained in:
17
spothole.py
17
spothole.py
@@ -1,9 +1,4 @@
|
||||
# Main script
|
||||
from time import sleep
|
||||
|
||||
import gevent
|
||||
from gevent import monkey; monkey.patch_all()
|
||||
|
||||
import importlib
|
||||
import logging
|
||||
import signal
|
||||
@@ -33,7 +28,8 @@ run = True
|
||||
def shutdown(sig, frame):
|
||||
global run
|
||||
|
||||
logging.info("Stopping program, this may take a few seconds...")
|
||||
logging.info("Stopping program, this may take up to 60 seconds...")
|
||||
web_server.stop()
|
||||
for p in spot_providers:
|
||||
if p.enabled:
|
||||
p.stop()
|
||||
@@ -44,7 +40,6 @@ def shutdown(sig, frame):
|
||||
lookup_helper.stop()
|
||||
spots.close()
|
||||
alerts.close()
|
||||
run = False
|
||||
|
||||
|
||||
# Utility method to get a spot provider based on the class specified in its config entry.
|
||||
@@ -84,7 +79,6 @@ if __name__ == '__main__':
|
||||
|
||||
# Set up web server
|
||||
web_server = WebServer(spots=spots, alerts=alerts, status_data=status_data, port=WEB_SERVER_PORT)
|
||||
web_server.start()
|
||||
|
||||
# Fetch, set up and start spot providers
|
||||
for entry in config["spot-providers"]:
|
||||
@@ -114,6 +108,7 @@ if __name__ == '__main__':
|
||||
|
||||
logging.info("Startup complete.")
|
||||
|
||||
while run:
|
||||
gevent.sleep(1)
|
||||
exit(0)
|
||||
# Run the web server. This is the blocking call that keeps the application running in the main thread, so this must
|
||||
# be the last thing we do. web_server.stop() triggers an await condition in the web server which finishes the main
|
||||
# thread.
|
||||
web_server.start()
|
||||
|
||||
Reference in New Issue
Block a user