Skip to content
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

fix: stop event loop on Connector.close #410

Merged
merged 5 commits into from
Jul 26, 2022
Merged

fix: stop event loop on Connector.close #410

merged 5 commits into from
Jul 26, 2022

Conversation

jackwotherspoon
Copy link
Collaborator

Background threads used for Connector() are daemon threads and by default do not get killed until process exits. Since we are spinning up these threads with loop.run_forever the thread will not get killed until the event loop is closed. Which in the current state is when the Python program exits, which is not efficient for long running programs.

To fix this, we should call loop.stop when closing a Connector object which will in turn kill the background daemon thread.

Closes #409

@jackwotherspoon jackwotherspoon self-assigned this Jul 26, 2022
@jackwotherspoon jackwotherspoon requested a review from kurtisvg July 26, 2022 14:26
tests/unit/test_connector.py Outdated Show resolved Hide resolved
google/cloud/sql/connector/connector.py Outdated Show resolved Hide resolved
@jackwotherspoon jackwotherspoon requested a review from kurtisvg July 26, 2022 16:22
@jackwotherspoon jackwotherspoon merged commit 5cda924 into main Jul 26, 2022
@jackwotherspoon jackwotherspoon deleted the loop-cleanup branch July 26, 2022 21:16
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.

Asyncio loop not cleared on closing / garbage collection
2 participants