This repository was archived by the owner on Jun 29, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathrun.py
More file actions
executable file
·47 lines (39 loc) · 1.25 KB
/
run.py
File metadata and controls
executable file
·47 lines (39 loc) · 1.25 KB
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
45
46
47
#!/usr/bin/env python3
"""FAForever API server
Usage:
run.py
run.py [-d | -aio] -p 80
run.py [-d | -aio] --port=80
Options:
-h Show this screen
-aio Use aiohttp
-d Enable debug mode
-p --port=<port> Listen on given port [default: 8080].
"""
import logging
import sys
from docopt import docopt
from api import app, api_init
if __name__ == '__main__':
args = docopt(__doc__)
app.config.from_object('config')
api_init()
port = int(args.get("--port"))
print('listen on port {0}'.format(port))
root = logging.getLogger()
loghandler = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter('%(asctime)s - %(name)-25s - %(levelname)-5s - %(message)s')
loghandler.setFormatter(formatter)
root.addHandler(loghandler)
if args.get('-d'):
root.setLevel(logging.DEBUG)
loghandler.setLevel(logging.DEBUG)
app.debug = True
app.run(host='0.0.0.0', port=port)
else:
print('with aiohttp')
from aiohttp_wsgi import serve
from concurrent.futures import ThreadPoolExecutor
app.logger.setLevel(logging.INFO)
with ThreadPoolExecutor(max_workers=1) as executor:
serve(app, executor=executor, port=port)