| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4aa37f7 commit 7da73d8
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,6 +23,7 @@ | |||
| 23 | 23 | from __future__ import annotations | |
| 24 | 24 | ||
| 25 | 25 | import asyncio | |
| 26 | + import contextlib | ||
| 26 | 27 | import heapq | |
| 27 | 28 | import queue | |
| 28 | 29 | import random | |
@@ -793,17 +794,16 @@ def cancel(self) -> None: | |||
| 793 | 794 | """Cancel the browser.""" | |
| 794 | 795 | assert self.zc.loop is not None | |
| 795 | 796 | 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): | ||
| 803 | 805 | if not self.zc.loop.is_closed(): | |
| 804 | 806 | self.zc.loop.call_soon_threadsafe(self._async_cancel) | |
| 805 | - except RuntimeError: | ||
| 806 | - pass | ||
| 807 | 807 | self.join() | |
| 808 | 808 | ||
| 809 | 809 | def run(self) -> None: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments