Skip to content

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

Merged
ryantm merged 2 commits intomainfrom
rtm-10-11-background-task-instead
Oct 11, 2024
Merged

[websocket] use background tasks instead of cleanup function #100
ryantm merged 2 commits intomainfrom
rtm-10-11-background-task-instead

Conversation

@ryantm
Copy link
Copy Markdown
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
Copy Markdown
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
from websockets import WebSocketCommonProtocol

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

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
@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