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 iteration over message handlers #797

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pychromecast/socket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ def new_cast_status(self, cast_status):
for namespace in self.app_namespaces:
if namespace in self._handlers:
self._ensure_channel_connected(self.destination_id)
for handler in self._handlers[namespace]:
for handler in set(self._handlers[namespace]):
handler.channel_connected()

def _gen_request_id(self):
Expand Down Expand Up @@ -730,7 +730,7 @@ def _route_message(self, message, data: dict):
)

# message handlers
for handler in self._handlers[message.namespace]:
for handler in set(self._handlers[message.namespace]):
try:
handled = handler.receive_message(message, data)

Expand Down Expand Up @@ -773,8 +773,8 @@ def _cleanup(self):
except Exception: # pylint: disable=broad-except
pass

for namespace in self._handlers.values():
for handler in namespace:
for handlers in self._handlers.values():
for handler in set(handlers):
try:
handler.tear_down()
except Exception: # pylint: disable=broad-except
Expand Down Expand Up @@ -1050,7 +1050,7 @@ def handle_channel_disconnected(self):
"""Handles a channel being disconnected."""
for namespace in self.app_namespaces:
if namespace in self._handlers:
for handler in self._handlers[namespace]:
for handler in set(self._handlers[namespace]):
handler.channel_disconnected()

self.app_namespaces = []
Expand Down