Fixed bug where suspended tasks would not be purged upon exiting

This commit is contained in:
Nocturn9x 2022-02-26 19:35:03 +01:00
parent 587fba2dad
commit f38e508ef6
3 changed files with 9 additions and 4 deletions

View File

@ -644,6 +644,8 @@ class AsyncScheduler:
self.debugger.on_task_exit(task)
if task.last_io:
self.io_release_task(task)
if task in self.suspended:
self.suspended.remove(task)
# If the pool has finished executing or we're at the first parent
# task that kicked the loop, we can safely reschedule the parent(s)
if task.pool is None:
@ -651,6 +653,8 @@ class AsyncScheduler:
if task.pool.done():
self.reschedule_joiners(task)
elif task.exc:
if task in self.suspended:
self.suspended.remove(task)
task.status = "crashed"
if task.exc.__traceback__:
# TODO: We might want to do a bit more complex traceback hacking to remove any extra

View File

@ -8,6 +8,7 @@ async def sender(sock: giambio.socket.AsyncSocket, q: giambio.Queue):
while True:
await sock.send_all(b"yo")
await q.put((0, ""))
await giambio.sleep(1)
async def receiver(sock: giambio.socket.AsyncSocket, q: giambio.Queue):

View File

@ -12,11 +12,11 @@ async def main():
start = giambio.clock()
try:
async with giambio.with_timeout(12) as pool:
await pool.spawn(child, 7) # This will complete
await giambio.sleep(2) # This will make the code below wait 2 seconds
await pool.spawn(child, 7) # This will complete
await giambio.sleep(2) # This will make the code below wait 2 seconds
await pool.spawn(child, 15) # This will not complete
await giambio.sleep(50)
await child(20) # Neither will this
await child(20) # Neither will this
await giambio.sleep(50) # Nor this
except giambio.exceptions.TooSlowError:
print("[main] One or more children have timed out!")
print(f"[main] Children execution complete in {giambio.clock() - start:.2f} seconds")