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

Panel widgets not working with fast async/ await functions #4237

Closed
MarcSkovMadsen opened this issue Dec 25, 2022 · 1 comment · Fixed by holoviz/param#684
Closed

Panel widgets not working with fast async/ await functions #4237

MarcSkovMadsen opened this issue Dec 25, 2022 · 1 comment · Fixed by holoviz/param#684
Labels
type: bug Something isn't correct or isn't working

Comments

@MarcSkovMadsen
Copy link
Collaborator

panel==0.14.2

I'm trying to add documentation on using Dask. Currently working on Async. I can see that the Terminal writes the same line twice when await is triggered right after terminal.write.

import panel as pn
import asyncio
import time
pn.extension("terminal", sizing_mode="stretch_width")

submit_button = pn.widgets.Button(name="Submit")

terminal = pn.widgets.Terminal(height=300, )

@pn.depends(submit_button, watch=True)
async def _handle_click(_):
    terminal.write(f"-----\n")
    terminal.write(f"start\n")
    
    # time.sleep(0.05)
    await asyncio.sleep(0.02)
    
    terminal.write(f"end\n")

component = pn.Column(
    submit_button,
    terminal,
).servable()

I would expect start to be written to the terminal once for every button click. Instead its written twice.

image

If you uncomment the line # time.sleep(0.05) I only get start written once per click.

@MarcSkovMadsen MarcSkovMadsen added the type: bug Something isn't correct or isn't working label Dec 25, 2022
@MarcSkovMadsen MarcSkovMadsen added this to the v0.14.3 milestone Dec 25, 2022
@MarcSkovMadsen MarcSkovMadsen changed the title Terminal not working well in async/ await function Terminal not working well in combination with async/ await Dec 25, 2022
@MarcSkovMadsen MarcSkovMadsen changed the title Terminal not working well in combination with async/ await Terminal and Button not working well in combination with async/ await Dec 26, 2022
@MarcSkovMadsen MarcSkovMadsen changed the title Terminal and Button not working well in combination with async/ await Panel widgets not working well in combination with async/ await Dec 26, 2022
@MarcSkovMadsen
Copy link
Collaborator Author

MarcSkovMadsen commented Dec 26, 2022

Here is a similar example using a Button.

import asyncio
import panel as pn

pn.extension()


submit_button = pn.widgets.Button(name="Submit")
@pn.depends(submit_button, watch=True)
async def _click(_):
    submit_button.disabled=True
    
    await asyncio.sleep(0.01)

    submit_button.disabled=False
    

submit_button.servable()

After clicking once I would expect the button to be enabled. But it is disabled

image

If I increase the sleep delay to 0.25 I don't see this problem.

@MarcSkovMadsen MarcSkovMadsen changed the title Panel widgets not working well in combination with async/ await Panel widgets not working well in combination with fast async/ await functions Dec 26, 2022
@MarcSkovMadsen MarcSkovMadsen changed the title Panel widgets not working well in combination with fast async/ await functions Panel widgets not working with fast async/ await functions Dec 26, 2022
@philippjfr philippjfr removed this from the v0.14.3 milestone Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants