I’m creating a bokeh app that every second updates a group of plots with data from an external data source. I use a periodic_callback for the update function. The problem is, when I close a browser window, the callback doesn’t get removed. So the app calls the update function much more often then it should, slowing down the app.
A simpler version of what I’m doing, that has the same problem is:
import time
from bokeh.plotting import curdoc
from bokeh.models.widgets import TextInput
class Plotter():
def init(self):
self.update_time_input = TextInput(value=str(1), title=“Update Time (seconds)”)
self.update_time_input.on_change(‘value’, self.update_time_change)
curdoc().add_root(self.update_time_input)
self.start()
def update_time_change(self,attrname, old, new):
curdoc().remove_periodic_callback(self._update)
curdoc().add_periodic_callback(self._update,int(float(new)*1000))
def start(self):
curdoc().add_periodic_callback(self._update, 1000)
def _update(self):
print “update”
print time.time()
plot = Plotter()
This just creates a text input to change how often the periodic_callback is called, and prints a time-stamp every update function.
I run the app with the command: bokeh serve --unused-session-lifetime 1000 --checked-unused-sessions 1000 --show app.py
The session lifetime commands don’t seem to effect anything I will have messages that say:
/app has 4 sessions with 3 unused
The unused sessions don’t seem to go away no matter what lifetime I give them.