question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Race condition when updating data source and x_range

See original GitHub issue

Software 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 a on_value callback on a TextInput. If a data source update and an update of the x_range are done sequentially in the update function, I would expect the displayed x_range to be determined by the values to which x_range.start and x_range.end were explicitly set.

  • Observed behavior Sometimes, the displayed x_range behaves as if the x_range had not been set at all. If a sufficiently long sleep is performed between the data source update and the x_range update, the x_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 desired_behavior

  • Actual behavior (sometimes) Obtained by commenting/removing the sleep in the above code example and typing 8 in the TextInput update_x_range_fails

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bryevdvcommented, Aug 3, 2021

TBH trying to take a quick look I am not seeing where setting post-initialization values for start or end 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

0reactions
bryevdvcommented, Jan 26, 2022

Noting there is a simpler reproducer in https://github.com/bokeh/bokeh/issues/11980

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is a Race Condition? - TechTarget
In computer memory or storage, a race condition may occur if commands to read and write a large amount of data are received...
Read more >
What is a race condition? - Stack Overflow
A race condition occurs when two or more threads can access shared data and they try to change it at the same time....
Read more >
Race condition vs. Data Race: the differences explained
Race conditions and Data Races can lead to unexpected behavior, and as an engineer it's important to know the differences between both.
Read more >
Race condition - Wikipedia
A race condition or race hazard is the condition of an electronics, software, or other system where the system's substantive behavior is dependent...
Read more >
What is a Race Condition? | Baeldung on Computer Science
Unlike race conditions, a data race on a particular platform has a strict definition that is not dependent on program semantics. This provides ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found