-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathdev_server.py
More file actions
35 lines (25 loc) · 819 Bytes
/
dev_server.py
File metadata and controls
35 lines (25 loc) · 819 Bytes
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
import os
import random
import shutil
from main import create_app, db
prometheus_dir = "var/prometheus"
os.environ["PROMETHEUS_MULTIPROC_DIR"] = prometheus_dir
if os.path.exists(prometheus_dir):
shutil.rmtree(prometheus_dir, True)
if not os.path.exists(prometheus_dir):
os.mkdir(prometheus_dir)
app = create_app(dev_server=True)
# Prevent DB connections and random numbers being shared
ppid = os.getpid()
@app.before_request
def fix_shared_state():
if os.getpid() != ppid:
db.engine.dispose()
random.seed()
import prometheus_client.multiprocess
@app.after_request
def prometheus_cleanup(response):
# this keeps livesum and liveall accurate
# other metrics will hang around until restart
prometheus_client.multiprocess.mark_process_dead(os.getpid())
return response