chia-blockchain/chia/util/safe_cancel_task.py
Kyle Altendorf 3b084a165b
configure isort to add the future annotations import (#13327)
* configure isort to add the future annotations import

* apply the new isort setting

* remove type ignores for new mypy (#13539)

https://pypi.org/project/mypy/0.981/

* another
2022-09-30 03:40:22 -05:00

15 lines
381 B
Python

from __future__ import annotations
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}")