-
Notifications
You must be signed in to change notification settings - Fork 947
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
Output.clear_output()
in a thread does not block until the output is cleared
#3260
Comments
Relatedly, the workaround I posted does not work reliably in JupyterLab (version 3.0.16). Here is a reproducer: import string
import threading
from ipywidgets import Output
from IPython.display import display
import time out1 = Output()
out1.append_stdout('hello\n')
display(out1) out2 = Output()
out2.append_stdout('hello\n')
display(out2) def run(out):
out.clear_output()
while out.outputs: # <-- one of the threads may get stuck in this loop
time.sleep(.01)
for c in string.ascii_letters:
out.append_stdout(c)
time.sleep(.1)
thread1 = threading.Thread(target=run, args=[out1])
thread2 = threading.Thread(target=run, args=[out2])
thread1.start()
thread2.start() For me, the typical outcome when running this is that only one of the outputs gets cleared and is then able to be updated. The other output stays as |
From this page, it seems like it is unsafe to use context managers with output widgets when multiple threads are involved. While your code does not explicitly use context managers, apparently the A workaround that you can use is to clear your output with E.g.
|
Thank you @raziqraif .. |
Note that due to ipython/ipykernel#1135 we should be able to change how this works in the future. |
I'm also seeing race-conditions with out = widgets.Output()
display(out)
out.append_stdout("Hello")
out.clear_output()
out.append_stdout("World") What I'm seeing is a short flash of Using So this issue seems to affect jupyterlab 4.2.4, ipywidgets 8.1.3 |
Description
I create an
Output
object on the main thread and display something on it. Then, in another thread, I try to clear the output and display other things on it. There is a surprising race condition that causes some of the things in the new thread to not be displayed. Specifically, the call toout.clear_output()
does not clear the output right away, so subsequent calls to the Output object will get dropped onceclear_output
finally takes effect.Reproduce
From IPython notebook:
For me, the output from the first cell can be
jklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
.abcdefghi
got cleared!To work around this, I currently do the following:
Expected behavior
I expect the output of
out
to be cleared inbad_clear
immediately afterout.clear_output()
is called. If it's too troublesome to do this, then I at least expect a note in the docstring and the example added here: #1794Context
Previous relevant issues: #1794 #1722 #1752
The text was updated successfully, but these errors were encountered: