Fix server shut down on exit.

If there's a websocket being waited on the shut down won't actually
happen. Add a new event for shut down and send it to break the websocket
out of its loop.
This commit is contained in:
Dan Albert
2022-02-25 17:12:00 -08:00
parent 2efe4f6c80
commit af4a718fc7
3 changed files with 12 additions and 0 deletions

View File

@@ -6,8 +6,10 @@ from threading import Thread
import uvicorn
from uvicorn import Config
from game.server import EventStream
from game.server.app import app
from game.server.settings import ServerSettings
from game.sim import GameUpdateEvents
class Server(uvicorn.Server):
@@ -34,4 +36,5 @@ class Server(uvicorn.Server):
yield
finally:
self.should_exit = True
EventStream.put_nowait(GameUpdateEvents().shut_down())
thread.join()