Cancel the future if possible. Returns True if the future was cancelled, False otherwise. A future cannot be cancelled if it is running or has already completed.
(self)
| 362 | _STATE_TO_DESCRIPTION_MAP[self._state]) |
| 363 | |
| 364 | def cancel(self): |
| 365 | """Cancel the future if possible. |
| 366 | |
| 367 | Returns True if the future was cancelled, False otherwise. A future |
| 368 | cannot be cancelled if it is running or has already completed. |
| 369 | """ |
| 370 | with self._condition: |
| 371 | if self._state in [RUNNING, FINISHED]: |
| 372 | return False |
| 373 | |
| 374 | if self._state in [CANCELLED, CANCELLED_AND_NOTIFIED]: |
| 375 | return True |
| 376 | |
| 377 | self._state = CANCELLED |
| 378 | self._condition.notify_all() |
| 379 | |
| 380 | self._invoke_callbacks() |
| 381 | return True |
| 382 | |
| 383 | def cancelled(self): |
| 384 | """Return True if the future was cancelled.""" |
no test coverage detected