Closing Bokeh session without closing the browser

Hi,

I am using Bokeh server with server_document to display multiple frontend tabs (managed by external React). Each tab opens additional websocket.

Is it possible to somehow close an existing session, so websocket will be closed? Preferably via JS (via server side can also help).

Thanks

Hi Meir,

Yes this is possible but Im not sure if my way is sort of hacky… basically if you search through bokehJS theres an object related to the web socket connection. I’ve modified the bokehJS code to my own custom version so that when a WS connection is created I also create a new global object (set to the window for example). Then, now that I have this WS connection instance, you can call the bokeh defined ‘.close’ function on it whenever you want.

In fact, theres slightly more to do to then ‘cleanup’ any remaining bokeh document related objects which can be found in the global ‘Bokeh’ object created by bokehJS…but thats the gist of it.

···

On Sun, Apr 8, 2018 at 6:07 PM, Meir Tseitlin [email protected] wrote:

Hi,

I am using Bokeh server with server_document to display multiple frontend tabs (managed by external React). Each tab opens additional websocket.

Is it possible to somehow close an existing session, so websocket will be closed? Preferably via JS (via server side can also help).

Thanks

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/8fde46d3-6c5b-485b-b47d-4727af387cc6%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi,

Looks like on the server side we can use bokeh.client.session (bokeh.client.session — Bokeh 3.3.2 Documentation) which has close method.

If session is created with with pull_session (as mentioned here - https://bokeh.pydata.org/en/latest/docs/user_guide/embed.html#app-sessions), we can do it with creating a custom API call to the application which in turn will access bokeh server to close the session from server side.

Yet, I am sure it can be done directly via BokehJS, but I don’t find any references to it…

···

On Sunday, April 8, 2018 at 8:36:45 PM UTC+3, omearac wrote:

Hi Meir,

Yes this is possible but Im not sure if my way is sort of hacky… basically if you search through bokehJS theres an object related to the web socket connection. I’ve modified the bokehJS code to my own custom version so that when a WS connection is created I also create a new global object (set to the window for example). Then, now that I have this WS connection instance, you can call the bokeh defined ‘.close’ function on it whenever you want.

In fact, theres slightly more to do to then ‘cleanup’ any remaining bokeh document related objects which can be found in the global ‘Bokeh’ object created by bokehJS…but thats the gist of it.

On Sun, Apr 8, 2018 at 6:07 PM, Meir Tseitlin [email protected] wrote:

Hi,

I am using Bokeh server with server_document to display multiple frontend tabs (managed by external React). Each tab opens additional websocket.

Is it possible to somehow close an existing session, so websocket will be closed? Preferably via JS (via server side can also help).

Thanks

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/8fde46d3-6c5b-485b-b47d-4727af387cc6%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

I’m away from the code right now but I believe if you search through bokehJS there’s a method called somewhere like “__on_open” for a websocket object. In that method I just have something like window.WS=_this

Then in my own JavaScript file which is also loaded (not using any “bokehJS callback”) I access the .WS variable and call the bokeh method “.close”.

If this doesn’t help I can post a snippet tmrw

···

On Apr 9, 2018, at 10:45 AM, Meir Tseitlin [email protected] wrote:

Hi,

Looks like on the server side we can use bokeh.client.session (https://bokeh.pydata.org/en/latest/docs/reference/client/session.html) which has close method.

If session is created with with pull_session (as mentioned here - https://bokeh.pydata.org/en/latest/docs/user_guide/embed.html#app-sessions), we can do it with creating a custom API call to the application which in turn will access bokeh server to close the session from server side.

Yet, I am sure it can be done directly via BokehJS, but I don’t find any references to it…

On Sunday, April 8, 2018 at 8:36:45 PM UTC+3, omearac wrote:

Hi Meir,

Yes this is possible but Im not sure if my way is sort of hacky… basically if you search through bokehJS theres an object related to the web socket connection. I’ve modified the bokehJS code to my own custom version so that when a WS connection is created I also create a new global object (set to the window for example). Then, now that I have this WS connection instance, you can call the bokeh defined ‘.close’ function on it whenever you want.

In fact, theres slightly more to do to then ‘cleanup’ any remaining bokeh document related objects which can be found in the global ‘Bokeh’ object created by bokehJS…but thats the gist of it.

On Sun, Apr 8, 2018 at 6:07 PM, Meir Tseitlin [email protected] wrote:

Hi,

I am using Bokeh server with server_document to display multiple frontend tabs (managed by external React). Each tab opens additional websocket.

Is it possible to somehow close an existing session, so websocket will be closed? Preferably via JS (via server side can also help).

Thanks

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/8fde46d3-6c5b-485b-b47d-4727af387cc6%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

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/b8ed1ac3-258a-4726-aa35-8f9bdccde9ff%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Just chiming in: feel free to open GH discussions if there are missing useful features around session management. There are definitely some things like timeout/disconnection notices, auto-reconnection, or manual reconnect options, etc that have crossed my mind but it would be good to have a wider discussion and see what people's real uses and needs are first.

Thanks,

Bryan

···

On Apr 9, 2018, at 10:06, 'Corey O'Meara' via Bokeh Discussion - Public <[email protected]> wrote:

I’m away from the code right now but I believe if you search through bokehJS there’s a method called somewhere like “__on_open” for a websocket object. In that method I just have something like window.WS=_this

Then in my own JavaScript file which is also loaded (not using any “bokehJS callback”) I access the .WS variable and call the bokeh method “.close”.

If this doesn’t help I can post a snippet tmrw

On Apr 9, 2018, at 10:45 AM, Meir Tseitlin <[email protected]> wrote:

Hi,

Looks like on the server side we can use bokeh.client.session (https://bokeh.pydata.org/en/latest/docs/reference/client/session.html\) which has `close` method.

If session is created with with `pull_session` (as mentioned here - https://bokeh.pydata.org/en/latest/docs/user_guide/embed.html#app-sessions\), we can do it with creating a custom API call to the application which in turn will access bokeh server to close the session from server side.

Yet, I am sure it can be done directly via BokehJS, but I don't find any references to it....

On Sunday, April 8, 2018 at 8:36:45 PM UTC+3, omearac wrote:
Hi Meir,

Yes this is possible but Im not sure if my way is sort of hacky... basically if you search through bokehJS theres an object related to the web socket connection. I've modified the bokehJS code to my own custom version so that when a WS connection is created I also create a new global object (set to the window for example). Then, now that I have this WS connection instance, you can call the bokeh defined '.close' function on it whenever you want.

In fact, theres slightly more to do to then 'cleanup' any remaining bokeh document related objects which can be found in the global 'Bokeh' object created by bokehJS..but thats the gist of it.

On Sun, Apr 8, 2018 at 6:07 PM, Meir Tseitlin <[email protected]> wrote:
Hi,

I am using Bokeh server with `server_document` to display multiple frontend tabs (managed by external React). Each tab opens additional websocket.

Is it possible to somehow close an existing session, so websocket will be closed? Preferably via JS (via server side can also help).

Thanks

--
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 bokeh+un...@continuum.io.
To post to this group, send email to bo...@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/8fde46d3-6c5b-485b-b47d-4727af387cc6%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
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/b8ed1ac3-258a-4726-aa35-8f9bdccde9ff%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
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/4D00F6CB-FD96-44A3-A014-FE469E447690%40googlemail.com\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.