dfdf
This commit is contained in:
@@ -23,6 +23,57 @@ _SOULSEEK_NOISE_SUBSTRINGS = (
|
||||
)
|
||||
|
||||
|
||||
@contextlib.asynccontextmanager
|
||||
async def _suppress_aioslsk_asyncio_task_noise() -> Any:
|
||||
"""Suppress non-fatal aioslsk task exceptions emitted via asyncio's loop handler.
|
||||
|
||||
aioslsk may spawn background tasks (e.g. direct peer connection attempts) that
|
||||
can fail with ConnectionFailedError. These are often expected and should not
|
||||
end a successful download with a scary "Task exception was never retrieved"
|
||||
traceback.
|
||||
|
||||
We only swallow those specific cases and delegate everything else to the
|
||||
previous/default handler.
|
||||
"""
|
||||
try:
|
||||
loop = asyncio.get_running_loop()
|
||||
except RuntimeError:
|
||||
# Not in an event loop.
|
||||
yield
|
||||
return
|
||||
|
||||
previous_handler = loop.get_exception_handler()
|
||||
|
||||
def _handler(loop: asyncio.AbstractEventLoop, context: Dict[str, Any]) -> None:
|
||||
try:
|
||||
exc = context.get("exception")
|
||||
msg = str(context.get("message") or "")
|
||||
# Only suppress un-retrieved task exceptions from aioslsk connection failures.
|
||||
if msg == "Task exception was never retrieved" and exc is not None:
|
||||
cls = getattr(exc, "__class__", None)
|
||||
name = getattr(cls, "__name__", "")
|
||||
mod = getattr(cls, "__module__", "")
|
||||
if name == "ConnectionFailedError" and str(mod).startswith("aioslsk"):
|
||||
return
|
||||
except Exception:
|
||||
# If our filter logic fails, fall through to default handling.
|
||||
pass
|
||||
|
||||
if previous_handler is not None:
|
||||
previous_handler(loop, context)
|
||||
else:
|
||||
loop.default_exception_handler(context)
|
||||
|
||||
loop.set_exception_handler(_handler)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
try:
|
||||
loop.set_exception_handler(previous_handler)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def _configure_aioslsk_logging() -> None:
|
||||
"""Reduce aioslsk internal log noise.
|
||||
|
||||
@@ -508,7 +559,8 @@ async def download_soulseek_file(
|
||||
client = SoulSeekClient(settings)
|
||||
with _suppress_aioslsk_noise():
|
||||
try:
|
||||
await client.start()
|
||||
async with _suppress_aioslsk_asyncio_task_noise():
|
||||
await client.start()
|
||||
await client.login()
|
||||
debug(f"[soulseek] Logged in as {login_user}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user