-
-
Notifications
You must be signed in to change notification settings - Fork 510
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
pn.state.on_session_destroyed() never called #3601
Comments
This needs to be documented better but def main_app():
pn.state.on_session_destroyed(destroyed)
return pn.Row("Test App") because inside the def created(session_context):
pn.state.on_session_destroyed(destroyed)
print("created")
pn.state.on_session_created(created) |
Thanks for this answer, yes its confusing that Also, i didnt have luck with your second suggestion of putting Follow up question, how might i get access to the |
Ok, yea i'm still confused. First, the Next, This is what i came up with, which does work, but doesn't seem very elegant.. import logging
import panel as pn
logging.basicConfig(
format="%(asctime)s.%(msecs)03d %(levelname)s {%(module)s} [%(funcName)s] %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
level=logging.DEBUG,
)
def destroyed(session_context):
print("destroyed")
raise KeyboardInterrupt
def created(session_context):
print("created")
def main_app():
pn.state.on_session_destroyed(destroyed)
return pn.Row("Test App")
pn.state.on_session_created(created)
try:
app = pn.serve(
{"Demo": main_app},
port=8080,
title="Demo",
show=True,
start=True,
autoreload=False,
)
except KeyboardInterrupt:
pass
print("complete")
|
You can run the server in a separate thread by passing |
Copy. This does seem nicer. Thanks for the help. import logging
import panel as pn
logging.basicConfig(
format="%(asctime)s.%(msecs)03d %(levelname)s {%(module)s} [%(funcName)s] %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
level=logging.DEBUG,
)
def destroyed(session_context):
print("destroyed")
app.stop()
def created(session_context):
print("created")
def main_app():
pn.state.on_session_destroyed(destroyed)
return pn.Row("Test App")
pn.state.on_session_created(created)
app = pn.serve(
{"Demo": main_app},
port=8080,
title="Demo",
show=True,
start=True,
autoreload=False,
threaded=True,
)
print("complete") |
ALL software version info
python 3.10
panel 0.13.1
Description of expected behavior and the observed behavior
I havent been able to get the
pn.state.on_session_destroyed()
callback to work,pn.state.on_session_created()
works as expected.Perhaps you can suggest a better approach for my usage case. I'm building an app that will be served locally for one user, and i want to be able to stop the server when the session is destroyed.
Complete, minimal, self-contained example code that reproduces the issue
Stack traceback and/or browser JavaScript console output
You can see that "created" was printed out as expected when the session was created, but when the session is destroyed 28s after the connection was closed, it never prints "destroyed"
The text was updated successfully, but these errors were encountered: