Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9a16be5

Browse filesBrowse files
authored
feat: improve ServiceBrowser performance by removing OrderedDict (#1148)
1 parent d3213d7 commit 9a16be5
Copy full SHA for 9a16be5

File tree

2 files changed

+7
-6
lines changed
Filter options

2 files changed

+7
-6
lines changed

‎src/zeroconf/_services/browser.py

Copy file name to clipboardExpand all lines: src/zeroconf/_services/browser.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import threading
2727
import warnings
2828
from abc import abstractmethod
29-
from collections import OrderedDict
3029
from typing import (
3130
TYPE_CHECKING,
3231
Callable,
@@ -302,7 +301,7 @@ def __init__(
302301
self.port = port
303302
self.multicast = self.addr in (None, _MDNS_ADDR, _MDNS_ADDR6)
304303
self.question_type = question_type
305-
self._pending_handlers: OrderedDict[Tuple[str, str], ServiceStateChange] = OrderedDict()
304+
self._pending_handlers: Dict[Tuple[str, str], ServiceStateChange] = {}
306305
self._service_state_changed = Signal()
307306
self.query_scheduler = QueryScheduler(self.types, delay, _FIRST_QUERY_DELAY_RANDOM_INTERVAL)
308307
self.done = False
@@ -551,5 +550,6 @@ def async_update_records_complete(self) -> None:
551550
552551
This method will be run in the event loop.
553552
"""
554-
while self._pending_handlers:
555-
self.queue.put(self._pending_handlers.popitem(False))
553+
for pending in self._pending_handlers.items():
554+
self.queue.put(pending)
555+
self._pending_handlers.clear()

‎src/zeroconf/asyncio.py

Copy file name to clipboardExpand all lines: src/zeroconf/asyncio.py
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ def async_update_records_complete(self) -> None:
8989
9090
This method will be run in the event loop.
9191
"""
92-
while self._pending_handlers:
93-
self._fire_service_state_changed_event(self._pending_handlers.popitem(False))
92+
for pending in self._pending_handlers.items():
93+
self._fire_service_state_changed_event(pending)
94+
self._pending_handlers.clear()
9495

9596

9697
class AsyncZeroconfServiceTypes(ZeroconfServiceTypes):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.