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

add_periodic_callback not working with pn.state.cache and --autoreload flag #2651

Closed
MarcSkovMadsen opened this issue Aug 22, 2021 · 2 comments
Labels
wontfix This will not be worked on

Comments

@MarcSkovMadsen
Copy link
Collaborator

Panel 0.12.1

If I run the below script using panel serve script.py --autoreload --show --port=5006 does not work.

If I run the below script using panel serve script.py --port=5007 it works.

periodic_callback_not_working.mp4
import datetime

import panel as pn

pn.extension(sizing_mode="stretch_both")

ACCENT_BASE_COLOR = "#DAA520"

if not "streaming_component" in pn.state.cache:
    streaming_component = pn.pane.Markdown("hello")
    def update():
        text = f"""# Last Update: {datetime.datetime.utcnow().strftime('%H:%M:%S.%f')}"""
        print(text)
        streaming_component.object = text
    pn.state.cache["streaming_component"]=streaming_component
    periodic_callback = pn.state.add_periodic_callback(callback=update, period=500)

streaming_component=pn.state.cache["streaming_component"]


panel = pn.Row(streaming_component, height=90)

template = pn.template.FastListTemplate(
    site="Awesome Panel",
    title="add_periodic_callback",
    logo="https://panel.holoviz.org/_static/logo_stacked.png",
    header_background=ACCENT_BASE_COLOR,
    accent_base_color=ACCENT_BASE_COLOR,
    main=[panel],
).servable()
@MarcSkovMadsen MarcSkovMadsen added TRIAGE Default label for untriaged issues type: bug Something isn't correct or isn't working and removed TRIAGE Default label for untriaged issues labels Aug 22, 2021
@MarcSkovMadsen MarcSkovMadsen added this to the 0.12.2 milestone Aug 22, 2021
@philippjfr philippjfr removed this from the 0.12.2 milestone Aug 31, 2021
@philippjfr
Copy link
Member

Interesting approach, but absolutely not a supported configuration. As I mentioned elsewhere add_periodic_callback adds a callback which is specific to a particular session. In this case --autoreload creates a session on launch, which is immediately cleaned up. Even without --autoreload this will break on second load of the app (or rather as soon as the initial session is cleaned up).

@philippjfr philippjfr added wontfix This will not be worked on and removed type: bug Something isn't correct or isn't working labels Aug 31, 2021
@philippjfr
Copy link
Member

Once #2661 you should be able to use that instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants