Race condition when updating data source and x_range
See original GitHub issueSoftware version info
- bokeh server on Debian 8 (vagrant virtual machine)
- Chrome 62.0.3202.94 (on MAC OS)
- bokeh 0.12.7, 0.12.9, 0.12.10, 0.12.11 (with
bokeh serve
) - python 2.7
- installed python packages
backports-abc==0.5
bokeh==0.12.11
certifi==2017.11.5
futures==3.2.0
Jinja2==2.10
MarkupSafe==1.0
numpy==1.13.3
pandas==0.21.0
python-dateutil==2.6.1
pytz==2017.3
PyYAML==3.12
singledispatch==3.4.0.3
six==1.11.0
tornado==4.5.2
Expected behavior vs. observed behavior
-
Expected behavior I would like to update both a data source and an
x_range
of some plot in aon_value
callback on aTextInput
. If a data source update and an update of thex_range
are done sequentially in the update function, I would expect the displayedx_range
to be determined by the values to whichx_range.start
andx_range.end
were explicitly set. -
Observed behavior Sometimes, the displayed
x_range
behaves as if thex_range
had not been set at all. If a sufficiently longsleep
is performed between the data source update and thex_range
update, thex_range
is then displayed in the browser as expected. There must hence be a race condition (I would assume on the JavaScript side).
Minimal code example
import pandas as pd
from bokeh.plotting import figure, curdoc
from bokeh.layouts import column
from bokeh.models.sources import ColumnDataSource
from bokeh.models.widgets import TextInput
from time import sleep
def dashboard():
all_data = pd.DataFrame({'y': [1, 2, 3] * 5,
'x': range(15)})
data_source = ColumnDataSource(all_data)
selector = TextInput()
plot = figure(plot_height=300, plot_width=1000, title='Example')
plot.line('x', 'y', source=data_source)
def updata_data(attr_name, old, new):
"""
If this sleep is removed or if the sleeping time is reduced to 1 ms,
the axis update sometimes fails.
"""
new_data = ColumnDataSource.from_df(all_data.query("x >= {}".format(new)))
data_source.data.update(**new_data)
#sleep(0.2)
plot.x_range.start = int(new) - 1.5
plot.x_range.end = 18.5
selector.on_change('value', updata_data)
curdoc().add_root(column(selector, plot))
dashboard()
Stack traceback and/or browser JavaScript console output
- Bokeh server
(bokeh_experiments) vagrant@jessie-test:~$ bokeh serve --port 5567 --show minimal_example.py
2017-12-05 17:34:13,953 Starting Bokeh server version 0.12.11 (running on Tornado 4.5.2)
2017-12-05 17:34:13,955 Bokeh app running at: http://localhost:5567/minimal_example
2017-12-05 17:34:13,955 Starting Bokeh server with process id: 874
2017-12-05 17:34:21,149 200 GET /static/js/bokeh-gl.min.js.map (10.0.2.2) 19.66ms
2017-12-05 17:34:21,155 200 GET /static/js/bokeh-widgets.min.js.map (10.0.2.2) 32.05ms
2017-12-05 17:34:21,250 200 GET /static/js/bokeh-tables.min.js.map (10.0.2.2) 125.31ms
2017-12-05 17:34:21,458 200 GET /static/js/bokeh.min.js.map (10.0.2.2) 346.86ms
2017-12-05 17:34:23,124 200 GET /minimal_example (10.0.2.2) 77.84ms
2017-12-05 17:34:23,388 101 GET /minimal_example/ws?bokeh-protocol-version=1.0&bokeh-session-id=4e2sdAyWmhyJ29VstqB7R47el0NfDQYXsBifEOSlNIoB (10.0.2.2) 0.48ms
2017-12-05 17:34:23,388 WebSocket connection opened
2017-12-05 17:34:23,389 ServerConnection created
- Browser console
[bokeh] setting log level to: 'info'
connection.js:194 [bokeh] Websocket connection 0 is now open
widget_box.js:108 [bokeh] WidgetBox mode is fixed, but no width specified. Using default of 300.
document.js:168 [bokeh] document idle at 76 ms
embed.js:291 Bokeh items were rendered successfully
Screenshots or screencasts of the bug in action
-
Desired behavior Obtained by uncommenting the sleep in the above code example and typing 8 in the
TextInput
-
Actual behavior (sometimes) Obtained by commenting/removing the sleep in the above code example and typing 8 in the
TextInput
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (5 by maintainers)
Top GitHub Comments
TBH trying to take a quick look I am not seeing where setting post-initialization values for
start
orend
would trigger an update. This may actually be just be a case of missing event plumbing.That said, approximately a dozen different little features multiplicatively converge on data ranges, making it one of the most complicated and convoluted parts of the entire codebase. I may be at the point of thinking we just have to start over for data-ranges in 3.x in order to find ways to separate and simplify things, so that one class is not so drastically overloaded. cc @mattpap
Noting there is a simpler reproducer in https://github.com/bokeh/bokeh/issues/11980