Fixes to cancellation

This commit is contained in:
Nocturn9x 2023-02-22 17:43:14 +01:00
parent 0560298f0f
commit f81071f3b2
2 changed files with 5 additions and 8 deletions

View File

@ -157,11 +157,11 @@ async def wait(task: Task) -> Any | None:
raise SchedulerError("a task cannot join itself")
if current not in task.joiners:
# Luckily we use a set, so this has O(1)
# complexity
# complexity on average
await join(task) # Waiting implies joining!
await syscall("wait", task)
if task.exc and task.state != TaskState.CANCELLED and task.propagate:
# Task raised an error that wasn't directly caused by a cancellation:
# The task raised an error that wasn't directly caused by a cancellation:
# raise it, but do so only the first time wait was called
task.propagate = False
raise task.exc
@ -184,7 +184,7 @@ async def cancel(task: Task, block: bool = False):
:type block: bool, optional
"""
await syscall("cancel", task, block)
await syscall("cancel", task)
if block:
await wait(task)
if not task.state == TaskState.CANCELLED:

View File

@ -422,7 +422,7 @@ class FIFOKernel:
self.handle_errors(partial(k.data.throw, exc), k.data)
self.reschedule_running()
def cancel(self, task: Task, block: bool = True):
def cancel(self, task: Task):
"""
Attempts to cancel the given task or
schedules cancellation for later if
@ -434,8 +434,7 @@ class FIFOKernel:
task.pending_cancellation = True
self.io_release_task(task)
self.paused.discard(task)
if not block:
self.reschedule_running()
self.reschedule_running()
def handle_errors(self, func: Callable, task: Task | None = None):
"""
@ -510,8 +509,6 @@ class FIFOKernel:
self.paused.discard(task)
self.io_release_task(task)
self.run_ready.extend(task.joiners)
if task is not self.current_task:
self.reschedule_running()
def join(self, task: Task):
"""