File tree Expand file tree Collapse file tree 1 file changed +21
-4
lines changed
Expand file tree Collapse file tree 1 file changed +21
-4
lines changed Original file line number Diff line number Diff line change 88 pyarrow = None
99import json
1010import os
11+ import sys
1112import decimal
1213from urllib .parse import urlparse
1314from uuid import UUID
@@ -516,20 +517,36 @@ def close(self) -> None:
516517 self ._close ()
517518
518519 def _close (self , close_cursors = True ) -> None :
520+ # Check if Python is shutting down
521+ shutting_down = sys .meta_path is None
522+
519523 if close_cursors :
520524 for cursor in self ._cursors :
521- cursor .close ()
525+ try :
526+ cursor .close ()
527+ except Exception :
528+ if not shutting_down :
529+ logger .debug ("Error closing cursor during connection close" , exc_info = True )
522530
523531 try :
524532 self .session .close ()
525533 except Exception as e :
526- logger .error (f"Attempt to close session raised a local exception: { e } " )
534+ if not shutting_down :
535+ logger .error (f"Attempt to close session raised a local exception: { e } " )
527536
528- TelemetryClientFactory .close (host_url = self .session .host )
537+ try :
538+ TelemetryClientFactory .close (host_url = self .session .host )
539+ except Exception :
540+ if not shutting_down :
541+ logger .debug ("Error closing telemetry client" , exc_info = True )
529542
530543 # Close HTTP client that was created by this connection
531544 if self .http_client :
532- self .http_client .close ()
545+ try :
546+ self .http_client .close ()
547+ except Exception :
548+ if not shutting_down :
549+ logger .debug ("Error closing HTTP client" , exc_info = True )
533550
534551 @property
535552 def autocommit (self ) -> bool :
You can’t perform that action at this time.
0 commit comments