Newer
Older
import argparse
from multiprocessing import Process
import uvicorn
from conf.defaults import server_conf
def parse_args():
parser = argparse.ArgumentParser(
description='Start model server with optional arguments',
)
parser.add_argument(
'--host',
default=server_conf['host'],
help='bind socket to this host'
)
parser.add_argument(
'--port',
default=str(server_conf['port']),
help='bind socket to this port',
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
45
46
47
48
49
50
51
52
53
54
)
parser.add_argument(
'--debug',
action='store_true',
help='display extra information that is helpful for debugging'
)
return parser.parse_args()
if __name__ == '__main__':
args = parse_args()
print('CLI args:\n' + str(args))
server_process = Process(
target=uvicorn.run,
args=('model_server.api:app',),
kwargs={
'app_dir': '.',
'host': args.host,
'port': int(args.port),
'log_level': 'debug',
'reload': False
},
daemon=True,
)
server_process.start()
if args.debug:
print('Running in debug mode')
print('Type "STOP" to stop server')
input_str = ''
while input_str.upper() != 'STOP':
input_str = input()
print('Finished')