Periodic_callback not closing

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.

Carson,

This is a known bug, it was recently discovered awhile back, but unfortunately lost in the shuffle:

  https://github.com/bokeh/bokeh/issues/3770

We will try to get out dev build with a fix in the very near future.

Bryan

···

On Apr 4, 2016, at 11:08 AM, [email protected] wrote:

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.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/5a0d081f-ccd9-41ba-b6c7-1090db63ae17%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Hi Carson,

Good news, I just tried your code after some updates on master, and it appears to be working as expected with the invocation:

  bokeh serve --unused-session-lifetime 1000 --check-unused-sessions 1000 --show app.py

(note: slight change to correct typo from what you had below, option is "--check-unused-sessions" not "--checked-unused-sessions")

You may find this works with yesterdays "dev6" build, and we should also have a "dev7" build out later today or tomorrow. Please let me know if this is working for you. Regarding 3770, I think perhaps the answer is additional documentation support, as well as decreasing the default timeout time, which is currently quite high. But if you have opinions, please do share them on that issue.

Thanks,

Bryan

···

On Apr 4, 2016, at 12:23 PM, Bryan Van de Ven <[email protected]> wrote:

Carson,

This is a known bug, it was recently discovered awhile back, but unfortunately lost in the shuffle:

  https://github.com/bokeh/bokeh/issues/3770

We will try to get out dev build with a fix in the very near future.

Bryan

On Apr 4, 2016, at 11:08 AM, [email protected] wrote:

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.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/5a0d081f-ccd9-41ba-b6c7-1090db63ae17%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.