Commit 57a438b2 authored by Philipp Hörist's avatar Philipp Hörist

Task: Don’t allow to cancel a finished task

parent efb63279
Pipeline #6714 passed with stages
in 30 seconds
......@@ -137,7 +137,7 @@ class Task:
return self._state
def add_done_callback(self, callback, weak=True):
if self._state in (TaskState.FINISHED, TaskState.CANCELLED):
if self._state.is_finished or self._state.is_cancelled:
raise RuntimeError('Task is finished')
if weak:
......@@ -169,7 +169,7 @@ class Task:
def _sub_task_completed(self, task):
self._sub_task = None
if self._state.is_cancelled:
if not self._state.is_running:
return
result = task.get_result()
......@@ -263,7 +263,7 @@ class Task:
self._finalize_context = context
def cancel(self):
if self._state.is_cancelled:
if not self._state.is_running:
return
self._state = TaskState.CANCELLED
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment