FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(core): use contextlib.suppress in ServiceBrowser.cancel and clari… · python-zeroconf/python-zeroconf@7da73d8 · GitHub

Commit 7da73d8

Browse files
committed
fix(core): use contextlib.suppress in ServiceBrowser.cancel and clarify comment
1 parent 4aa37f7 commit 7da73d8

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

‎src/zeroconf/_services/browser.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from __future__ import annotations
2424

2525
import asyncio
26+
import contextlib
2627
import heapq
2728
import queue
2829
import random
@@ -793,17 +794,16 @@ def cancel(self) -> None:
793794
"""Cancel the browser."""
794795
assert self.zc.loop is not None
795796
self.queue.put(None)
796-
# Skip scheduling _async_cancel when the loop is closed: a closed
797-
# loop rejects call_soon_threadsafe with RuntimeError. While the
798-
# loop is running, _async_cancel stops the query scheduler and
799-
# cancels the query-sender task; that is the normal cleanup path.
800-
# The is_closed() check is racy if cancel() runs concurrently with
801-
# Zeroconf.close(), so guard the schedule call as well.
802-
try:
797+
# While the loop is running, _async_cancel stops the query scheduler
798+
# and cancels the query-sender task — that is the normal cleanup
799+
# path. Skip scheduling solely because the loop is closed: a closed
800+
# loop rejects call_soon_threadsafe with RuntimeError. The
801+
# is_closed() check narrows the common case (loop already closed by
802+
# Zeroconf.close()) without paying for raise/catch; suppress covers
803+
# the residual is_closed() -> call_soon_threadsafe race window.
804+
with contextlib.suppress(RuntimeError):
803805
if not self.zc.loop.is_closed():
804806
self.zc.loop.call_soon_threadsafe(self._async_cancel)
805-
except RuntimeError:
806-
pass
807807
self.join()
808808

809809
def run(self) -> None:

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL