mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-09-21 00:24:37 +03:00
13 lines
345 B
Python
13 lines
345 B
Python
import asyncio
|
|
import logging
|
|
from typing import Optional
|
|
|
|
|
|
def cancel_task_safe(task: Optional[asyncio.Task], log: Optional[logging.Logger] = 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}")
|