diff --git a/structio/core/context.py b/structio/core/context.py index ca38484..f47a17f 100644 --- a/structio/core/context.py +++ b/structio/core/context.py @@ -29,6 +29,8 @@ class TaskScope: self.attempted_cancel: bool = False # Have we been cancelled? self.cancelled: bool = False + # Have we timed out? + self.timed_out: bool = False # Can we be indirectly cancelled? Note that this # does not affect explicit cancellations via the # cancel() method diff --git a/structio/core/kernels/fifo.py b/structio/core/kernels/fifo.py index cba0cb6..9d4ce52 100644 --- a/structio/core/kernels/fifo.py +++ b/structio/core/kernels/fifo.py @@ -249,6 +249,7 @@ class FIFOKernel(BaseKernel): def check_scopes(self): for scope in self.pool.scope.children: if scope.get_actual_timeout() <= self.clock.current_time(): + scope.timed_out = True if scope.silent: self.cancel_scope(scope) self.reschedule(scope.owner) @@ -447,6 +448,8 @@ class FIFOKernel(BaseKernel): # cancel() for a scope which it doesn't own, which # is an entirely reasonable thing to do self.cancel_task(scope.owner) + if scope.done(): + scope.cancelled = True def init_pool(self, pool: TaskPool): pool.outer = self.current_pool diff --git a/tests/timeouts.py b/tests/timeouts.py index 9fc9b73..d460588 100644 --- a/tests/timeouts.py +++ b/tests/timeouts.py @@ -8,7 +8,7 @@ async def test_silent(i, j): print(f"[test] Sleeping for {j} seconds") await structio.sleep(j) print( - f"[test] Finished in {structio.clock() - k:.2f} seconds (timed out: {scope.cancelled})" + f"[test] Finished in {structio.clock() - k:.2f} seconds (timed out: {scope.timed_out})" )