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)
| 356 | _STATE_TO_DESCRIPTION_MAP[self._state]) |
| 357 | |
| 358 | def cancel(self): |
| 359 | """Cancel the future if possible. |
| 360 | |
| 361 | Returns True if the future was cancelled, False otherwise. A future |
| 362 | cannot be cancelled if it is running or has already completed. |
| 363 | """ |
| 364 | with self._condition: |
| 365 | if self._state in [RUNNING, FINISHED]: |
| 366 | return False |
| 367 | |
| 368 | if self._state in [CANCELLED, CANCELLED_AND_NOTIFIED]: |
| 369 | return True |
| 370 | |
| 371 | self._state = CANCELLED |
| 372 | self._condition.notify_all() |
| 373 | |
| 374 | self._invoke_callbacks() |
| 375 | return True |
| 376 | |
| 377 | def cancelled(self): |
| 378 | """Return True if the future was cancelled.""" |
no test coverage detected