Cancel the future. If the future has not been started yet, it will never
    start running. If the future is already running, it will run until the
    worker function exists. The worker function can check if the future has
    been cancelled using the :meth:`cancelled` method.

    If the future has already been completed, it will not be marked as
    cancelled unless you set *mark_completed_as_cancelled* to :const:`True`.

    :param mark_completed_as_cancelled: If this is :const:`True` and the
      future has already completed, it will be marked as cancelled anyway.

def cancel(self, mark_completed_as_cancelled=False):
    """
    Cancel the future. If the future has not been started yet, it will never
    start running. If the future is already running, it will run until the
    worker function exists. The worker function can check if the future has
    been cancelled using the :meth:`cancelled` method.

    If the future has already been completed, it will not be marked as
    cancelled unless you set *mark_completed_as_cancelled* to :const:`True`.

    :param mark_completed_as_cancelled: If this is :const:`True` and the
      future has already completed, it will be marked as cancelled anyway.
    """

    with self._lock:
      if not self._completed or mark_completed_as_cancelled:
        self._cancelled = True
      callbacks = self._prepare_done_callbacks()
    callbacks()