ipywidgets
ipywidgets copied to clipboard
Rendering output from within async function does not work as intended
trafficstars
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