I have an API that retrieve financial data using asyncio. I am trying to integrate it with bokeh atm.
I simplified the behavior of the asyncio API to demonstrate my problem here, but basically lets consider that it retrieve some data and want to plot i every second like so:
from bokeh.models import ColumnDataSource
from bokeh.client import push_session
from bokeh.plotting import figure, curdoc
import asyncio
import numpy as np
x=0;y=0
async def udpate_data():
while True:
await asyncio.sleep(1)
global x,y
x+=1; y+=np.sin(x)
print(x)
source.stream(dict(x=,y=[y]))
source=ColumnDataSource(dict(x=,y=))
p=figure()
l=p.line(x=“x”,y=“y”,source=source)
session=push_session(curdoc(),session_id=“main”)
session.show(p)
loop=asyncio.get_event_loop()
loop.run_until_complete(udpate_data())
``
This is from an example on how to integrate bokeh and asyncio that I found here:
http://blog.angryturtle.com/2017/04/realtime-bokeh-plotting-with-asyncio.html
https://gist.github.com/sonium0/65cde09ec21d573281d1ce2ca33a6262
However, if i try to run the script (for instance saving it in /bokeh_test/main.py
and running it from ../
as bokeh serve bokeh_test
at first it seems like working as the shell displays:
2017-10-31 18:34:36,871 Starting Bokeh server version 0.12.10 (running on Tornado 4.5.2)
2017-10-31 18:34:36,873 Bokeh app running at: http://localhost:5006/bokeh
2017-10-31 18:34:36,873 Starting Bokeh server with process id: 1711
``
However if i go to my browser and try to connect to http://localhost:5006/bokeh, I receive error
2017-10-31 18:35:13,141 Failed to connect to server: HTTP 599: Timeout during request
2017-10-31 18:35:13,143 Error running application handler <bokeh.application.handlers.directory.DirectoryHandler object at 0x7f543dc50eb8>: Cannot p$
sh session document because we failed to connect to the server (to start the server, try the ‘bokeh serve’ command)
File “session.py”, line 370, in push:
raise IOError(“Cannot push session document because we failed to connect to the server (to start the server, try the ‘bokeh serve’ command)”) Traceba
ck (most recent call last):
File “/home/depot/.conda/envs/python36/lib/python3.6/site-packages/bokeh/application/handlers/code_runner.py”, line 125, in run
exec(self._code, module.dict)
File “/home/depot/wintergreen/test_scripts/bokeh3/main.py”, line 20, in
session=push_session(curdoc(),session_id=“main”)
File “/home/depot/.conda/envs/python36/lib/python3.6/site-packages/bokeh/util/api.py”, line 190, in wrapper
return obj(*args, **kw)
File “/home/depot/.conda/envs/python36/lib/python3.6/site-packages/bokeh/client/session.py”, line 161, in push_session
session.push(document)
File “/home/depot/.conda/envs/python36/lib/python3.6/site-packages/bokeh/util/api.py”, line 190, in wrapper
return obj(*args, **kw)
File “/home/depot/.conda/envs/python36/lib/python3.6/site-packages/bokeh/client/session.py”, line 370, in push
raise IOError(“Cannot push session document because we failed to connect to the server (to start the server, try the ‘bokeh serve’ command)”)
OSError: Cannot push session document because we failed to connect to the server (to start the server, try the ‘bokeh serve’ command)
``
I am a beginner programmer and unfamiliar with asyncio and tornado. I do not want to convert my existing app to tornado as it is quite developed already.
Thank you for your help,
Best,
Vincent