forked from bokeh/bokeh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocserver.py
76 lines (59 loc) · 1.78 KB
/
docserver.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from __future__ import print_function
import flask
import os
import sys
import threading
import time
import webbrowser
import tornado
from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
_basedir = os.path.join("..", os.path.dirname(__file__))
app = flask.Flask(__name__, static_folder="/unused")
PORT=5009
http_server = HTTPServer(WSGIContainer(app))
@app.route('/')
def welcome():
return """
<h1>Welcome to the Bokeh documentation server</h1>
You probably want to go to <a href="/en/latest/index.html"> Index</a>
"""
@app.route('/en/latest/<path:filename>')
def send_pic(filename):
return flask.send_from_directory(
os.path.join(_basedir,"sphinx/build/html/"), filename)
def open_browser():
# Child process
time.sleep(0.5)
webbrowser.open("http://localhost:%d/en/latest/index.html" % PORT, new="tab")
data = {}
def serve_http():
data['ioloop'] = IOLoop()
http_server.listen(PORT)
IOLoop.instance().start()
def shutdown_server():
ioloop = data['ioloop']
ioloop.add_callback(ioloop.stop)
print("Asked Server to shut down.")
def ui():
try:
time.sleep(0.5)
input("Press <ENTER> to exit...\n")
except:
pass
if __name__ == "__main__":
if tornado.version_info[0] == 4:
print('docserver.py script requires tornado 5 or higher')
sys.exit(1)
print("\nStarting Bokeh plot server on port %d..." % PORT)
print("Visit http://localhost:%d/en/latest/index.html to see plots\n" % PORT)
t_server = threading.Thread(target=serve_http)
t_server.start()
t_browser = threading.Thread(target=open_browser)
t_browser.start()
ui()
shutdown_server()
t_server.join()
t_browser.join()
print("Server shut down.")