-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserve.py
executable file
·54 lines (41 loc) · 1.63 KB
/
serve.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
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
import logging
from argparse import ArgumentParser
from logging.handlers import RotatingFileHandler
from multiprocessing import Process, Queue
from os import path
import globals
from WebApp import app
from game.logic import Logic
log = logging.getLogger()
log_dir = path.dirname(__file__)
if not log_dir:
log_dir = "."
if __name__ == '__main__':
# Parse command line arguments
args = ArgumentParser()
args.add_argument("--debug", action="store_true")
args.add_argument("--log-level", type=int, default=logging.INFO)
opts = args.parse_args()
# Configure logging
logging.basicConfig(level=logging.INFO, handlers=[
RotatingFileHandler("{}/{}.log".format(log_dir, __file__.split('/')[-1][:-3]), maxBytes=1280000, backupCount=1),
], format="[%(asctime)s] {%(name)s:%(lineno)d} %(levelname)s - %(message)s")
stream = logging.StreamHandler()
stream.setLevel(opts.log_level)
stream.setFormatter(logging.Formatter("[%(asctime)s] {%(name)s:%(lineno)d} %(levelname)s - %(message)s"))
logging.getLogger("apscheduler").setLevel(opts.log_level)
logging.getLogger("apscheduler").propagate = False
log.addHandler(stream)
# Access ComQueue singleton
q = globals.ComQueue()
# Set up communications queue
procComQueue = Queue()
q.setComQueue(procComQueue)
# Create the gameLogic Process
gameLogic = Process(target=Logic().run, args=[procComQueue])
gameLogic.start()
# Run the Flask server here in the parent
app.run(debug=False, host="::", port=5000)
# Wait for the gameLogic process to finish. Prevents Zombie processes
gameLogic.join()