Minor fix to timeout test and added timed_out field

This commit is contained in:
Mattia Giambirtone 2023-07-10 12:14:14 +02:00
parent 351a212ccd
commit 4d50130d53
Signed by: nocturn9x
GPG Key ID: 8270F9F467971E59
3 changed files with 6 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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})"
)