-
Notifications
You must be signed in to change notification settings - Fork 1
/
wsgi_uvicorn.py
44 lines (39 loc) · 1.25 KB
/
wsgi_uvicorn.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
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
"""Application Web Server Gateway Interface - uvicorn."""
import logging
import os
import sys
# import uvicorn
from uvicorn import Config, Server
import uvicorn
from loguru import logger
from mvc_demo.app.asgi import get_app
from mvc_demo.config.application import settings
from mvc_demo.core.loguru_logs import global_log_config
# https://stackoverflow.com/questions/68979130/gunicorn-uvicorn-run-programatically-or-via-command-line
def run_dev_wsgi(
host=os.getenv("FASTAPI_HOST", "127.0.0.1"),
port=os.getenv("FASTAPI_PORT", "8000"),
workers=int(os.getenv("FASTAPI_WORKERS", 2)),
):
"""Run uvicorn WSGI with ASGI workers."""
logger.info("Start uvicorn WSGI with ASGI workers.")
sys.exit(
uvicorn.run(
"mvc_demo.app.asgi:application",
host=host,
port=int(port),
reload=True,
# Workers are not used when reload = True
workers=int(workers),
lifespan="off",
log_config=None,
access_log=True,
)
)
if __name__ == "__main__":
run_dev_wsgi(
host=os.getenv("FASTAPI_HOST", "127.0.0.1"),
port=os.getenv("FASTAPI_PORT", "8000"),
workers=int(os.getenv("FASTAPI_WORKERS", 2)),
)