def cancel(self) -> None:
        """Request cancellation of a scheduled async task, if any.

        .. note::
            Wait until task is cancelled before returning control to caller.
        """
        with self:
            with self._scheduled_action_lock:
                if self._scheduled_action is None:
                    return
                logger.warning('Cancelling long running task %s', self._scheduled_action)
            self._is_cancelled = True

        self._cancellable.cancel()
        self._finish_event.wait()

        with self:
            self.reset_scheduled_action()
Request cancellation of a scheduled async task, if any.

        .. note::
            Wait until task is cancelled before returning control to caller.
        
patroni/async_executor.py