Skip to content

fix: Respect display.progress_bar=None in background threads#16715

Open
shuoweil wants to merge 28 commits into
mainfrom
shuowei-anywidget-extraneous-output
Open

fix: Respect display.progress_bar=None in background threads#16715
shuoweil wants to merge 28 commits into
mainfrom
shuowei-anywidget-extraneous-output

Conversation

@shuoweil
Copy link
Copy Markdown
Contributor

Captures the progress bar option from the initiating thread and propagates it via events to background callbacks, ensuring options like None are respected.

Fixes #<461829560> 🦕

@shuoweil shuoweil self-assigned this Apr 17, 2026
@shuoweil shuoweil requested review from a team as code owners April 17, 2026 23:31
@shuoweil shuoweil requested review from GarrettWu and sycai and removed request for a team and sycai April 17, 2026 23:31
@shuoweil shuoweil force-pushed the shuowei-anywidget-extraneous-output branch from de201ee to d887714 Compare April 17, 2026 23:33
@shuoweil shuoweil marked this pull request as draft April 17, 2026 23:35
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a mechanism to pass the progress_bar configuration through BigQuery events, allowing for more granular control over progress bar display. It updates several event classes to include a progress_bar field and modifies the callback logic to prioritize this field over global settings. Feedback suggests defining the 'fallback_to_global' sentinel as a constant to improve maintainability and refactoring the event mapping logic in create_bq_event_callback to reduce code duplication.

Comment thread packages/bigframes/bigframes/core/events.py Outdated
Comment thread packages/bigframes/bigframes/session/_io/bigquery/__init__.py Outdated
@shuoweil shuoweil force-pushed the shuowei-anywidget-extraneous-output branch from dce2e04 to 42e4a50 Compare April 17, 2026 23:49
@shuoweil shuoweil marked this pull request as ready for review April 20, 2026 22:54
@shuoweil shuoweil requested review from TrevorBergeron, chelsea-lin and sycai and removed request for sycai April 23, 2026 17:56
@shuoweil shuoweil closed this Apr 27, 2026
@tswast tswast reopened this Apr 28, 2026
@tswast
Copy link
Copy Markdown
Contributor

tswast commented Apr 28, 2026

This PR doesn't touch the thread localility of the configuration object. Please continue with this fix.


import bigframes.session.executor

_FALLBACK_TO_GLOBAL = "fallback_to_global"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally "default" would communicate this more succinctly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Replaced _FALLBACK_TO_GLOBAL with _DEFAULT = "default".

@shuoweil shuoweil requested a review from tswast May 1, 2026 23:39
@shuoweil shuoweil added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 4, 2026
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 4, 2026
Copy link
Copy Markdown
Contributor

@tswast tswast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sync with main so that the tests can re-run.

import google.cloud.bigquery._job_helpers
import google.cloud.bigquery.job.query
import google.cloud.bigquery.table
from google.cloud.bigquery.job.query import QueryPlanEntry
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the fully qualified name below. According to Google style, import modules not classes or functions.

location: Optional[str] = None
job_id: Optional[str] = None
request_id: Optional[str] = None
progress_bar: Optional[str] = _DEFAULT
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are 3.10+ now, we can use the recommended | None instead of Optional for clarity.

Suggested change
progress_bar: Optional[str] = _DEFAULT
progress_bar: str| None = _DEFAULT

Also, instead of general str, consider using Literal with the allowed values.

def from_bqclient(
cls,
event: google.cloud.bigquery._job_helpers.QuerySentEvent,
progress_bar: Optional[str] = _DEFAULT,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, | None and potentially Literal as well.

@shuoweil shuoweil requested a review from tswast May 8, 2026 21:07
location: str | None = None
job_id: str | None = None
request_id: str | None = None
progress_bar: Literal["default", "auto", "notebook", "terminal"] | None = _DEFAULT
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"progress_bar" isn't really state about the event, is it? Could you describe to me again what this is trying to solve?

Consider an alternative where the progress bar type is attached to the subscriber, instead, as that seems to be more appropriate. Or another alternative in which we wrap the events with some sort of "CellState" that gives an indicator of the current execution context, of which the progress_bar could be a property of that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Tim, thanks for the suggestions.

I looked into the first alternative (attaching the progress bar type to the subscriber), but it doesn't quite work for what we are trying to solve. The progress_bar option is thread-local and needs to be captured from the initiating thread at the moment the query starts. Since subscribers are typically long-lived (session-scoped), they cannot easily capture this per-query context. Furthermore, the callbacks from the BigQuery client library run in a background thread where the initiating thread's local storage is not accessible.

Therefore, I took your second alternative: I removed progress_bar from the event classes and instead wrapped the events in an EventEnvelope (acting as the execution context/'CellState' you suggested). This envelope is created in the callback (which captures the initiating thread's option via a closure) and carries the progress_bar setting along with the event to the subscribers.

This keeps the events clean of display preferences while solving the cross-thread propagation issue. Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants