From 5c9e7eeb6f1c7db64a38d6efb2ba5c0b30ed7ee8 Mon Sep 17 00:00:00 2001 From: Maarten Breddels Date: Sat, 7 Nov 2026 20:02:19 +0100 Subject: [PATCH 1/2] fix: do not define and wrap a function for every widget _create_widget defined a new @contextlib.contextmanager function for every widget to wrap hold_trait_notifications. The decorator runs functools.wraps, which sets __name__, __doc__ and other attributes on the new function. On free-threaded Python (3.14t) setting an attribute on a function object stops all threads, so rendering many widgets stopped the world many times per second. hold_trait_notifications is now a functools.partial of one module-level context manager, which behaves the same. Co-Authored-By: Claude Opus 5.5 --- reacton/core.py | 18 ++++++++++-------- reacton/core_test.py | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/reacton/core.py b/reacton/core.py index f2ef0ac..2246753 100644 --- a/reacton/core.py +++ b/reacton/core.py @@ -517,14 +517,10 @@ def _create_widget(self, kwargs): try: try: widget = self.component.widget(**kwargs) - hold_trait_notifications = widget.hold_trait_notifications - - @contextlib.contextmanager - def hold_trait_notifications_extra(*args, **kwargs): - with rc, hold_trait_notifications(*args, **kwargs): - yield - - widget.hold_trait_notifications = hold_trait_notifications_extra + # A partial of one module-level context manager, not a @contextlib.contextmanager defined here: + # that decorator runs functools.wraps for every widget, and on free-threaded Python setting + # attributes on a function object stops all threads. + widget.hold_trait_notifications = functools.partial(_hold_trait_notifications_extra, rc, widget.hold_trait_notifications) if self._meta: widget._react_meta = dict(self._meta) @@ -3423,3 +3419,9 @@ def Fragment(children: List[Element]): # not a public api yet, used in solara for now only. # lifecycle of context objects are linked to the lifecycle of the component _component_context_manager_classes: List[Any] = [] + + +@contextlib.contextmanager +def _hold_trait_notifications_extra(rc, hold_trait_notifications, *args, **kwargs): + with rc, hold_trait_notifications(*args, **kwargs): + yield diff --git a/reacton/core_test.py b/reacton/core_test.py index 579f37a..2a98167 100644 --- a/reacton/core_test.py +++ b/reacton/core_test.py @@ -4437,3 +4437,28 @@ def Level(): with pytest.raises(ValueError): rc.close() # close() raises the error of the failed render again assert time.monotonic() - start < 2 + + +def test_create_widget_does_not_wrap_a_function_per_widget(): + # on free-threaded Python, functools.wraps (setting attributes on a function) stops all threads, + # so creating a widget should not define and wrap a new function + import functools + + @react.component + def Test(): + with w.VBox() as main: + for i in range(10): + w.IntSlider(value=i) + return main + + with unittest.mock.patch("functools.update_wrapper", wraps=functools.update_wrapper) as update_wrapper: + box, rc = react.render(Test(), handle_error=False) + assert update_wrapper.call_count == 0 + slider = rc.find(widgets.IntSlider).widgets[0] + changes = [] + slider.observe(lambda change: changes.append(change["new"]), "value") + with slider.hold_trait_notifications(): + slider.value = 42 + assert changes == [] + assert changes == [42] + rc.close() From efb34a463ade00d8c1ec6d5e6dce0f22e97ccb73 Mon Sep 17 00:00:00 2001 From: Maarten Breddels Date: Sat, 7 Nov 2026 20:09:30 +0100 Subject: [PATCH 2/2] ci: install six for bqplot bqplot<0.13 imports six but does not declare it, and our test environment no longer pulls it in through another package, so collecting the tests failed with ModuleNotFoundError. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/unittest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index 6b32831..dfdc7fd 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -50,7 +50,7 @@ jobs: path: ./dist - name: Install run: | - pip install `echo dist/*.whl`[dev] "bqplot<0.13" "pandas<3" "ruff==0.8.3" "ipyvue${{ matrix.ipyvue }}" "ipyvuetify${{ matrix.ipyvue }}" + pip install `echo dist/*.whl`[dev] "bqplot<0.13" six "pandas<3" "ruff==0.8.3" "ipyvue${{ matrix.ipyvue }}" "ipyvuetify${{ matrix.ipyvue }}" - name: test env: REACTON_FAST: ${{ matrix.reacton-fast }}