I'm trying to clear ipwidget outputs from inside a thread
For example, I want to make a counter that counts to 10, runs in a thread, and only shows the current number.
Code
import ipywidgets as widgets
import time
from IPython.display import display, HTML
from concurrent.futures import ThreadPoolExecutor
output = widgets.Output()
display(output)
def my_foo():
for count in range(10):
output.clear_output(wait=True)
output.append_display_data(HTML(f"count {count}"))
time.sleep(1)
with ThreadPoolExecutor() as executor:
executor.submit(my_foo)
Desired Output
the final output for the above code should just be
count 9
Actual Ouput
count 0
count 1
count 2
count 3
count 4
count 5
count 6
count 7
count 8
count 9