-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunserver.py
37 lines (33 loc) · 1.01 KB
/
runserver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from sanic_script import Command, Option
from app import create_app
from signal import signal, SIGINT
import os
import asyncio
import uvloop
class RunServerCommand(Command):
app = create_app()
option_list = (
Option('--host', '-h', dest='host'),
Option('--port', '-p', dest='port'),
)
def run(self, *args, **kwargs):
self.app.run(
host=os.getenv('APP_HOST'),
port=int(os.getenv('APP_PORT')),
debug=os.getenv('APP_DEBUG'),
ssl=None,
workers=int(os.getenv('APP_WORKERS'))
)
asyncio.set_event_loop(uvloop.new_event_loop())
server = self.app.create_server(
host=os.getenv('APP_HOST'),
port=int(os.getenv('APP_PORT')),
debug=os.getenv('APP_DEBUG')
)
signal(SIGINT, lambda s, f: loop.stop())
loop = asyncio.get_event_loop()
task = asyncio.ensure_future(server)
try:
loop.run_forever()
except:
loop.stop()