in google/cloud/sql/connector/connector.py [0:0]
def close(self) -> None:
"""Close Connector by stopping tasks and releasing resources."""
if self._loop.is_running():
close_future = asyncio.run_coroutine_threadsafe(
self.close_async(), loop=self._loop
)
# Will attempt to safely shut down tasks for 3s
close_future.result(timeout=3)
# if background thread exists for Connector, clean it up
if self._thread:
if self._loop.is_running():
# stop event loop running in background thread
self._loop.call_soon_threadsafe(self._loop.stop)
# wait for thread to finish closing (i.e. loop to stop)
self._thread.join()