-
Notifications
You must be signed in to change notification settings - Fork 1
/
flask-app.py
59 lines (46 loc) · 1.26 KB
/
flask-app.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
54
55
56
57
58
59
from flask import Flask, render_template
import main
import threading
import time
import logging
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)
__license__ = "GNU GENERAL PUBLIC LICENSE"
__authors__ = "Ole Schmidt, Matthias Andres, Jonathan Gärtner"
__version__ = "1.0 - 'Heart's On Fire'"
# variables that are accessible from anywhere
data = {}
last_website_access = 0.0
running = True
def simulation():
global data
global running
while True: # Updates the simulation
if last_website_access + 3 <= time.time():
running = False
break
data = main.tick()
time.sleep(0.3)
app = Flask(__name__)
@app.route('/')
def index():
return render_template("index.html", bus_stops=main.bus_stops, center=main.center)
@app.route("/update")
def update():
global running
global last_website_access
last_website_access = time.time()
if running:
return data
else:
simu = threading.Thread(target=simulation)
simu.start()
running = True
return data
if __name__ == "__main__":
# lock to control access to variable
dataLock = threading.Lock()
# thread handler
simu = threading.Thread(target=simulation)
simu.start()
app.run(debug=True)