Files
chia-blockchain/chia/util/safe_cancel_task.py
Matt HauffandGitHub 40db4635a8 [LABS-245] Enable PEP604 Ruff rules (#20269)
* Enable PEP604 Ruff rules

* Fix harcoded signature in test

* Hack CLVMStreamable test with note to fast follow
2025-11-18 12:34:00 -08:00

16 lines
379 B
Python

# Package: utils
from __future__ import annotations
import asyncio
import logging
def cancel_task_safe(task: asyncio.Task[None] | None, log: logging.Logger | None = None) -> None:
if task is not None:
try:
task.cancel()
except Exception as e:
if log is not None:
log.error(f"Error while canceling task.{e} {task}")