Commit 7e959b9
authored
Fix: Defer TableWidget import to prevent ZMQ port conflicts (#2309)
This PR addresses a flaky ZMQError: Address already in use that
occasionally occurred during parallel notebook test execution.
**Problem:**
The bigframes.display module eagerly imported anywidget and traitlets at
module load time (`bigframes/display/__init__.py`). This meant that when
multiple Jupyter kernels were spun up simultaneously by nox for parallel
testing, they would all try to initialize traitlets.HasTraits objects
with sync=True properties. This led to race conditions and ZMQ port
conflicts, causing notebook tests (including those that did not directly
use anywidget like `streaming_dataframe.ipynb`) to fail. Log is
[here](https://fusion2.corp.google.com/invocations/72088900-0196-4441-944b-ad68e491a8f8/targets/bigframes%2Fpresubmit%2Fnotebook/log).
**Solution:**
The TableWidget class import in `bigframes/display/__init__.py` has been
refactored to use Python's `__getattr__` for lazy loading. This ensures
that anywidget and traitlets are only imported and their associated
kernel communication channels are initialized when display.TableWidget
is actually accessed by the code. This prevents premature initialization
and eliminates the port collision race condition during parallel test
startup.
Fixes #<465768150> 🦕1 parent 719b278 commit 7e959b9
1 file changed
+28
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
| 19 | + | |
21 | 20 | | |
22 | | - | |
23 | 21 | | |
24 | | - | |
25 | | - | |
26 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
0 commit comments