Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Periodic callback don't stop in Django #1125

Closed
hoxbro opened this issue Mar 2, 2020 · 7 comments
Closed

Periodic callback don't stop in Django #1125

hoxbro opened this issue Mar 2, 2020 · 7 comments
Labels
bokeh Request is for change in bokeh

Comments

@hoxbro
Copy link
Member

hoxbro commented Mar 2, 2020

ALL software version info

Python 3.7.6
Panel 8.0
Bokeh 1.4.0
Django 3.0.3
Channels 2.4.0
Windows 10

Description of expected behavior and the observed behavior

I'm trying to create a Django site which have a widget with a periodic callback, so a plot is updated every 10 seconds. In principle I have combined two of your examples a Django example and a periodic callback example.

I have got this work both with Django's python manage.py runserver and Panel's panel serve panel_example.py. But I have noticed that when I leave the site without stopping the periodic callback with the widget itself that it keeps running forever in Django, where Panel is running for ~30 seconds. Is there a way to get Django to work like Panel and only run for a small amount of time after a user leave the site?

I have very limited experience with Django and Bokeh interaction so it could be that I'm missing something very obvious or there are better alternatives to what I'm doing.

Complete, minimal, self-contained example code that reproduces the issue

See periodic_example.zip with an example of the problem, I'm using the commands mentioned above to start Django or Panel. I'm printing the current time when the function with a periodical callback is called.

@philippjfr philippjfr added the type: docs Related to the Panel documentation and examples label Mar 10, 2020
@hoxbro
Copy link
Member Author

hoxbro commented Mar 11, 2020

I think it is a bug that PeriodicCallback is running "forever" with Django when the user closes the browser without pressing the stop button.

I seems to be related to bokeh.io.curdoc.add_periodic_callback in PeriodicCallback which do not register when the user leaves the site.

@hoxbro
Copy link
Member Author

hoxbro commented Jun 17, 2020

The problem stills is still here with newer versions of Panel (0.10.0a6) and Bokeh (2.1.0). Updated code.

I have screen recorded the problem to show the how Panel stops after 30 seconds of closing the browser and Django keeps running forever. I have attached the screen recordings periodic_videos.zip and converted them to Gif:

Panel
panel

Django
django

@philippjfr
Copy link
Member

Sounds like the server cleanup handlers aren't correctly triggered when running via Django. It's likely we'll have to fix this upstream in Bokeh.

@hoxbro
Copy link
Member Author

hoxbro commented Jul 29, 2020

Could see their had been some updates with periodic callbacks in #1507 so I tried to see if it had solved the problem. Unfortunately it did not solve it but then again it was a long shot. I was running version 0.10.0a17.post4+g844c883.

Also looked into Bokeh´s Django implementation and found out I could register a window/tab closing with the function WSConsumers.disconnect in the file bokeh.server.django.consumers.py. I was not able to communicate between Django and Bokeh/Panel and communicate that the windows was closed, but maybe another one which has more experienced with that could be able to do it.

@hoxbro hoxbro changed the title Periodic callback don't stop Periodic callback don't stop in Django Jul 29, 2020
@philippjfr philippjfr added bokeh Request is for change in bokeh and removed type: docs Related to the Panel documentation and examples labels Aug 23, 2020
@hoxbro
Copy link
Member Author

hoxbro commented Oct 15, 2020

I have found out I can get the periodic callback to stop by changing the following lines from:

    async def disconnect(self, close_code):
        pass

to:

    async def disconnect(self, close_code):
        self.connection.session.destroy()

Maybe this could be the solution to my problem? I have not a Bokeh development environment setup on my computer, so I have not ran any of their tests.

@philippjfr
Copy link
Member

Ooh, yeah that seems like it would work. Maybe just submit a PR and we can discuss and further test it from there.

@hoxbro
Copy link
Member Author

hoxbro commented Oct 16, 2020

Fixed upstream in bokeh/bokeh#10578

@hoxbro hoxbro closed this as completed Oct 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bokeh Request is for change in bokeh
Projects
None yet
Development

No branches or pull requests

2 participants