def cancel_task_safe(self, task: Optional[asyncio.Task]):
    if (task is not None):
        try:
            task.cancel()
        except Exception as e:
            self.log.error(f'Error while canceling task.{e} {task}')
def cancel_task_safe(self, task: Optional[asyncio.Task]):
    if (task is not None):
        try:
            task.cancel()
        except Exception as e:
            self.log.error(f'Error while canceling task.{e} {task}')