-
Notifications
You must be signed in to change notification settings - Fork 133
fix: Adding Python shutdown check in _close to fix sys.meta_path is None error #730
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| pyarrow = None | ||
| import json | ||
| import os | ||
| import sys | ||
| import decimal | ||
| from urllib.parse import urlparse | ||
| from uuid import UUID | ||
|
|
@@ -516,20 +517,36 @@ def close(self) -> None: | |
| self._close() | ||
|
|
||
| def _close(self, close_cursors=True) -> None: | ||
| # Check if Python is shutting down | ||
| shutting_down = sys.meta_path is None | ||
|
|
||
| if close_cursors: | ||
| for cursor in self._cursors: | ||
| cursor.close() | ||
| try: | ||
| cursor.close() | ||
| except Exception: | ||
| if not shutting_down: | ||
| logger.debug("Error closing cursor during connection close", exc_info=True) | ||
|
Comment on lines
+525
to
+529
|
||
|
|
||
| try: | ||
| self.session.close() | ||
| except Exception as e: | ||
| logger.error(f"Attempt to close session raised a local exception: {e}") | ||
| if not shutting_down: | ||
| logger.error(f"Attempt to close session raised a local exception: {e}") | ||
|
|
||
| TelemetryClientFactory.close(host_url=self.session.host) | ||
| try: | ||
| TelemetryClientFactory.close(host_url=self.session.host) | ||
| except Exception: | ||
| if not shutting_down: | ||
| logger.debug("Error closing telemetry client", exc_info=True) | ||
|
Comment on lines
+537
to
+541
|
||
|
|
||
| # Close HTTP client that was created by this connection | ||
| if self.http_client: | ||
| self.http_client.close() | ||
| try: | ||
| self.http_client.close() | ||
| except Exception: | ||
| if not shutting_down: | ||
| logger.debug("Error closing HTTP client", exc_info=True) | ||
|
Comment on lines
+545
to
+549
|
||
|
|
||
| @property | ||
| def autocommit(self) -> bool: | ||
|
|
||
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.
The shutdown check variable is computed once at the beginning of
_close, but Python shutdown state could change during the execution of this method. Consider checkingsys.meta_path is Nonedirectly in each exception handler for more accurate shutdown detection.