<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def cancel(self):
 """Cancel the execution of the async function, if possible. This method marks the future as done and sets the :class:`Cancelled` exception. A future that is not running can always be cancelled. However when a future is running, the ability to cancel it depends on the pool implementation. For example, a fiber pool can cancel running fibers but a thread pool cannot. Return ``True`` if the future could be cancelled, ``False`` otherwise. """

        # We leverage/abuse our _done Event's thread lock as our own lock.
        # Since it's a private copy it should be OK, and it saves some memory.
        # Just be sure that we don't modify the event with the lock held.
        with self._lock:
            if self._state not in (self.S_PENDING, self.S_RUNNING):
                return False
            self._result = Cancelled('cancelled by Future.cancel()')
            self._state = self.S_EXCEPTION
            self._done.set()
            return True