-
Notifications
You must be signed in to change notification settings - Fork 322
fix: add timeout parameter to to_dataframe and to_arrow met… #2354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+257
−55
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c908a5c
fix(bigquery): add timeout parameter to to_dataframe and to_arrow met…
chalmerlowe f57810c
fix(bigquery): address review feedback - update _EmptyRowIterator sig…
chalmerlowe 031adf1
fix(bigquery): update tests to expect timeout parameter
chalmerlowe 39febf9
test(bigquery): add unit tests for timeout logic in _pandas_helpers.py
chalmerlowe a8e2d3f
fix: resolve EmptyRowIterator test failures and lint error\n\n- Insta…
chalmerlowe 43e6a40
Update tests/unit/test_table.py
chalmerlowe 5acd054
Merge branch 'main' into fix/to-dataframe-timeout
chalmerlowe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may wonder why we switched away from using a contextmanager here.
Here's a breakdown of the change:
Manual Pool Creation: Instead of the
withstatement, the code now creates theThreadPoolExecutordirectly:pool = concurrent.futures.ThreadPoolExecutor(max_workers=max(1, total_streams))Conditional Shutdown: The finally block now uses a
wait_on_shutdownboolean flag:pool.shutdown(wait=wait_on_shutdown)This flag is set to
Falseonly when aTimeoutErroris raised.Timeout Handling: Inside the while
not_done:loop, there's new logic to check if theelapsed time has exceeded the specified timeout. If it has, it raises a
concurrent.futures.TimeoutErrorand setswait_on_shutdowntoFalse.Why this change?
The standard context manager for
ThreadPoolExecutoralways waits for all futures to completeupon exiting the block. This behavior is not desirable when a
timeoutis implemented. If thedownload times out, we want to stop waiting for the worker threads immediately and not block
until they all finish.
By manually managing the pool and using the
wait_on_shutdownflag, we can tell thepool.shutdown()method not to wait for the threads to complete if atimeouthas occurred.This allows the
TimeoutErrorto be propagated up quickly, rather than being stuck waiting forthreads that are potentially hanging.
So, the change was necessary to ensure the timeout parameter works effectively and the
function doesn't hang unnecessarily when the timeout duration is exceeded. The core logic of
submitting tasks to the pool and retrieving results from the queue remains very similar, but
the shutdown process is now more nuanced to handle timeouts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!