Fix: Defer TableWidget import to prevent ZMQ port conflicts #2309
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 likestreaming_dataframe.ipynb) to fail. Log is here.Solution:
The TableWidget class import in
bigframes/display/__init__.pyhas 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> 🦕