-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.py
executable file
·39 lines (28 loc) · 910 Bytes
/
server.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
import datetime
import logging
import os
from unittest.mock import patch
import uvicorn
from uvicorn.supervisors import multiprocess
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# The ping/pong in the multiprocess supervisor does not work correctly in
# Google Cloud Run. See https://github.com/encode/uvicorn/discussions/2399
class Process(multiprocess.Process):
def ping(self, *args, **kwargs):
return True
@patch('uvicorn.supervisors.multiprocess.Process', Process)
def main():
logger.info("Starting Uvicorn.")
port = int(os.environ.get('PORT', 8000))
reload = os.environ.get('UVICORN_RELOAD', 'false').lower() == 'true'
uvicorn.run(
app='orthocal.asgi:application',
host='0.0.0.0',
port=port,
lifespan='off',
log_level='debug',
reload=reload,
)
if __name__ == '__main__':
main()