Skip to content
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
19 changes: 18 additions & 1 deletion sendspin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import asyncio
import logging
import platform
import sys
import uuid
Expand All @@ -13,6 +14,8 @@

from aiosendspin.models.core import DeviceInfo

logger = logging.getLogger(__name__)

_T = TypeVar("_T")

# Check if eager_start is supported (Python 3.12+)
Expand Down Expand Up @@ -61,11 +64,25 @@ def create_task(

TASKS.add(task)
task.add_done_callback(TASKS.discard)
task.add_done_callback(lambda t: t.exception() if not t.cancelled() else None)
task.add_done_callback(_log_task_exception)

return task


def _log_task_exception(task: asyncio.Task[Any]) -> None:
"""Log a fire-and-forget background task failure instead of swallowing it.

Retrieving the exception suppresses "exception was never retrieved"
warnings, but the previous lambda then discarded it — every background
failure (hook/amixer/PulseAudio volume errors included) was invisible.
"""
if task.cancelled():
return
exc = task.exception()
if exc is not None:
logger.error("Background task %r failed", task.get_name(), exc_info=exc)


def _detect_mac_address() -> str | None:
"""Return a stable hardware MAC address, or None if only a synthesized one is available.

Expand Down
Loading