-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
45 lines (36 loc) · 1003 Bytes
/
plot.py
File metadata and controls
45 lines (36 loc) · 1003 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
36
37
38
39
40
41
42
43
44
45
from time import sleep
from flask import render_template
import threading
import signal
from flask import Flask
app = Flask(__name__)
app.debug = True
from bokeshif import Bokeshif
class Killable(threading.Thread):
def __init__(self, **kwargs):
super(Killable, self).__init__(**kwargs)
self._stop = threading.Event()
def stop(self):
self._stop.set()
threads = []
def cleanup_threads(*args):
i = 0
for thread in threads:
thread.stop()
thread.join()
i = i+1
return 'Cleaned up {0} threads'.format(i)
def serve_app(bk):
while True:
bk.reload()
sleep(0.2)
signal.signal(signal.SIGTERM, cleanup_threads)
@app.route('/')
def index():
bokeshif = Bokeshif()
thread = Killable(target=serve_app, args=[bokeshif])
thread.start()
threads.append(thread)
return render_template('plot.html', autoload_script=bokeshif.embed_tag)
if __name__ == '__main__':
app.run()