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

[websocket] use background tasks instead of cleanup function #100

Merged
merged 2 commits into from
Oct 11, 2024

Conversation

ryantm
Copy link
Contributor

@ryantm ryantm commented Oct 11, 2024

Why

What changed

  • Revert cleanup commit
  • Add background websocket task storage

Test plan

  • Ran a pytest, and didn't see "Pending task destroyed" exceptions

@ryantm ryantm requested a review from a team as a code owner October 11, 2024 21:23
@ryantm ryantm requested review from jackyzha0 and removed request for a team October 11, 2024 21:23
Why
===
* The cleanup function added a burden on the caller to make sure the
tasks were awaited.
* Instead, follow the advice of
https://docs.python.org/3/library/asyncio-task.html#asyncio.create_task
and store them in the background properly

What changed
===
* Revert cleanup commit
* Add background websocket task storage

Test plan
===
* Ran a pytest, and didn't see "Pending task destroyed" exceptions
@ryantm ryantm force-pushed the rtm-10-11-background-task-instead branch from fa07599 to 1c344d9 Compare October 11, 2024 21:23
Copy link
Member

@jackyzha0 jackyzha0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm but would wait for someone with more python experience to approve :)

@ryantm ryantm added the minor Bump minor version label Oct 11, 2024
@@ -5,6 +5,7 @@
from websockets import WebSocketCommonProtocol

logger = logging.getLogger(__name__)
_background_tasks: set[asyncio.Task] = set()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine. don't love the idea of having another global, but the alternative is to re-add all the complexity. lgtm!

@ryantm ryantm merged commit a8418ec into main Oct 11, 2024
3 checks passed
@ryantm ryantm deleted the rtm-10-11-background-task-instead branch October 11, 2024 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor Bump minor version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants