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

Rendering output from within async function does not work as intended #3901

Open
and3rson opened this issue Apr 9, 2024 · 0 comments
Open

Comments

@and3rson
Copy link

and3rson commented Apr 9, 2024

Description

When modifying outputs from async functions, modifying components attributes (and doing prints) works, but re-rendering outputs does not.

Reproduce

Consider code which attempts to re-render the output from within async function:

%gui asyncio
import asyncio
import ipywidgets as widgets

buttons = widgets.Output()
lines = widgets.Output()

display(buttons, lines)

async def func():
    for i in range(5):
        # Render new button
        buttons.clear_output()
        with buttons:
            display(widgets.Button(description=str(i)))
    
        # Append new line
        with lines:
            print(i)

_ = asyncio.ensure_future(func())

This re-renders the button 5 times and prints 5 messages as expected:
зображення

However, when adding a delay inside the function:

  ...
  async def func():
      for i in range(5):
+         await asyncio.sleep(0.1)
    
          # Render new button
          ...

...the button output never updates and gets stuck at initially rendered instance. However, prints still work fine:
зображення

Expected behavior

with some_output: display(...) should always update UI, irregardless from where it was called from.

Context

  • ipywidgets version 8.1.2
  • Operating System and version: Arch Linux
  • Browser and version: Mozilla Firefox 125.0b6
@and3rson and3rson changed the title Displaying new widgets from within async function does not work as intended Rendering output from within async function does not work as intended Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant