Make web server restart without hanging.
This commit is contained in:
parent
44494f8e60
commit
f03a3d9377
1 changed files with 8 additions and 2 deletions
|
@ -5,6 +5,7 @@ from sanic.response import html, text, file, redirect
|
||||||
from sanic.response import json as resp_json
|
from sanic.response import json as resp_json
|
||||||
from sanic_cors import CORS
|
from sanic_cors import CORS
|
||||||
from syncer import sync
|
from syncer import sync
|
||||||
|
import asyncio
|
||||||
|
|
||||||
from jinja2 import Environment, FileSystemLoader
|
from jinja2 import Environment, FileSystemLoader
|
||||||
from urllib.parse import unquote
|
from urllib.parse import unquote
|
||||||
|
@ -349,7 +350,7 @@ def restart(request):
|
||||||
# Don't use reloader, it causes Nested Processes!
|
# Don't use reloader, it causes Nested Processes!
|
||||||
def WebServer(player_to: List[Queue], player_from: List[Queue], state: StateManager):
|
def WebServer(player_to: List[Queue], player_from: List[Queue], state: StateManager):
|
||||||
|
|
||||||
global player_to_q, player_from_q, server_state, api
|
global player_to_q, player_from_q, server_state, api, app
|
||||||
player_to_q = player_to
|
player_to_q = player_to
|
||||||
player_from_q = player_from
|
player_from_q = player_from
|
||||||
server_state = state
|
server_state = state
|
||||||
|
@ -370,6 +371,11 @@ def WebServer(player_to: List[Queue], player_from: List[Queue], state: StateMana
|
||||||
debug=True,
|
debug=True,
|
||||||
auto_reload=False
|
auto_reload=False
|
||||||
))
|
))
|
||||||
sleep(1)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
break
|
break
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
if loop:
|
||||||
|
loop.close()
|
||||||
|
if app:
|
||||||
|
app.stop()
|
||||||
|
del app
|
||||||
|
|
Loading…
Reference in a new issue