-
Notifications
You must be signed in to change notification settings - Fork 966
Open
Description
Description
Updating a widget in the background, as advertised in the doc, fails.
Reproduce
Open a notebook and copy-paste the code (from the documentation):
import threading
from IPython.display import display
import ipywidgets as widgets
import time
progress = widgets.FloatProgress(value=0.0, min=0.0, max=1.0)
def work(progress):
total = 100
for i in range(total):
time.sleep(0.2)
progress.value = float(i+1)/total
thread = threading.Thread(target=work, args=(progress,))
display(progress)
thread.start()
Running it yields an error:
Exception in thread Thread-5 (work):
Traceback (most recent call last):
File "[/storage/tools/anaconda/202501/lib/python3.12/threading.py", line 1075](https://localhost:8962/storage/tools/anaconda/202501/lib/python3.12/threading.py#line=1074), in _bootstrap_inner
self.run()
File "[/storage/tools/anaconda/202501/lib/python3.12/site-packages/ipykernel/ipkernel.py", line 788](https://localhost:8962/storage/tools/anaconda/202501/lib/python3.12/site-packages/ipykernel/ipkernel.py#line=787), in run_closure
_threading_Thread_run(self)
File "[/storage/tools/anaconda/202501/lib/python3.12/threading.py", line 1012](https://localhost:8962/storage/tools/anaconda/202501/lib/python3.12/threading.py#line=1011), in run
self._target(*self._args, **self._kwargs)
File "[/tmp/ipykernel_60690/3988194817.py", line 11](https://localhost:8962/tmp/ipykernel_60690/3988194817.py#line=10), in work
File "[/storage/tools/anaconda/202501/lib/python3.12/site-packages/traitlets/traitlets.py", line 716](https://localhost:8962/storage/tools/anaconda/202501/lib/python3.12/site-packages/traitlets/traitlets.py#line=715), in __set__
self.set(obj, value)
File "[/storage/tools/anaconda/202501/lib/python3.12/site-packages/traitlets/traitlets.py", line 706](https://localhost:8962/storage/tools/anaconda/202501/lib/python3.12/site-packages/traitlets/traitlets.py#line=705), in set
obj._notify_trait(self.name, old_value, new_value)
File "[/storage/tools/anaconda/202501/lib/python3.12/site-packages/traitlets/traitlets.py", line 1513](https://localhost:8962/storage/tools/anaconda/202501/lib/python3.12/site-packages/traitlets/traitlets.py#line=1512), in _notify_trait
self.notify_change(
File "[/storage/tools/anaconda/202501/lib/python3.12/site-packages/ipywidgets/widgets/widget.py", line 700](https://localhost:8962/storage/tools/anaconda/202501/lib/python3.12/site-packages/ipywidgets/widgets/widget.py#line=699), in notify_change
self.send_state(key=name)
File "[/storage/tools/anaconda/202501/lib/python3.12/site-packages/ipywidgets/widgets/widget.py", line 586](https://localhost:8962/storage/tools/anaconda/202501/lib/python3.12/site-packages/ipywidgets/widgets/widget.py#line=585), in send_state
self._send(msg, buffers=buffers)
File "[/storage/tools/anaconda/202501/lib/python3.12/site-packages/ipywidgets/widgets/widget.py", line 825](https://localhost:8962/storage/tools/anaconda/202501/lib/python3.12/site-packages/ipywidgets/widgets/widget.py#line=824), in _send
self.comm.send(data=msg, buffers=buffers)
File "[/storage/tools/anaconda/202501/lib/python3.12/site-packages/comm/base_comm.py", line 144](https://localhost:8962/storage/tools/anaconda/202501/lib/python3.12/site-packages/comm/base_comm.py#line=143), in send
self.publish_msg(
File "[/storage/tools/anaconda/202501/lib/python3.12/site-packages/ipykernel/comm/comm.py", line 42](https://localhost:8962/storage/tools/anaconda/202501/lib/python3.12/site-packages/ipykernel/comm/comm.py#line=41), in publish_msg
parent=self.kernel.get_parent(),
^^^^^^^^^^^^^^^^^^^^^^^^
File "[/storage/tools/anaconda/202501/lib/python3.12/site-packages/ipykernel/kernelbase.py", line 797](https://localhost:8962/storage/tools/anaconda/202501/lib/python3.12/site-packages/ipykernel/kernelbase.py#line=796), in get_parent
return self._shell_parent.get()
^^^^^^^^^^^^^^^^^^^^^^^^
LookupError: <ContextVar name='shell_parent' at 0x7fc4699136f0>
Expected behavior
What is described in the doc should happen: the progress bar gets updated at regular intervals. It used to work. Started to fail since a recent conda update --all.
Context
- ipywidgets version 8.1.7
- Operating System and version: Fedora 42
- Browser and version: Firefox 143 (same error on jupyterlab desktop)
If using JupyterLab
- JupyterLab version: JupyterLab v4.4.9
Installed Labextensions
jupyterlab_pygments v0.3.0 enabled OK (python, jupyterlab_pygments)
jupyter-leaflet v0.20.0 enabled OK
jupyter-matplotlib v0.11.8 enabled OK
@jupyter-widgets/jupyterlab-manager v5.0.15 enabled OK (python, jupyterlab_widgets)
@jupyter-notebook/lab-extension v7.4.7 enabled OK
Other labextensions (built into JupyterLab)
Metadata
Metadata
Assignees
Labels
No labels