def cancel(self, msg='<STR_LIT>', exc_type=CancelledError):
with self._lock:<EOL><INDENT>if not self.done():<EOL><INDENT>should_announce_done = False<EOL>logger.debug('<STR_LIT>', self, msg)<EOL>self._exception = exc_type(msg)<EOL>if self._status == '<STR_LIT>':<EOL><INDENT>should_announce_done = True<EOL><DEDENT>self._status = '<STR_LIT>'<EOL>if should_announce_done:<EOL><INDENT>self.announce_done()<EOL><DEDENT><DEDENT><DEDENT>
Cancels the TransferFuture

        :param msg: The message to attach to the cancellation
        :param exc_type: The type of exception to set for the cancellation