Skip to content

Race condition in slider value validation #6814

@ssunkara1

Description

@ssunkara1
from IPython.html.widgets import *
from IPython.display import display
a = IntSlider(description='Test')
display(a)
a.min = 20
a.value = 50
print a.value
## displays 20 instead of 50. Although the slider visually is at 50

What is happening is, the value is set from the Javascript side on change of min. This is happening not necessarily before the value is set on the python side in the next statement.

I was able to avoid the issue by setting the value on the min_changed function on the python side and not updating it from JS.

    def _handle_min_changed(self, name, old, new):
        """Make sure the max is always >= the min and change value if needed."""
        if new > self.max:
            raise ValueError("setting min > max")
        if self.value < self.min:
            self.value = self.min

What do you guys think will be the best way to deal with this?

Thanks,
Srinivas

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions