diff --git a/giambio/__init__.py b/giambio/__init__.py index c00ffb0..3ef8670 100644 --- a/giambio/__init__.py +++ b/giambio/__init__.py @@ -41,5 +41,5 @@ __all__ = [ "current_task", "new_event_loop", "debug", - "skip_after" + "skip_after", ] diff --git a/giambio/core.py b/giambio/core.py index ed5d9dc..6a74379 100644 --- a/giambio/core.py +++ b/giambio/core.py @@ -422,9 +422,9 @@ class AsyncScheduler: pool.timed_out = True for task in pool.tasks: if not task.done(): - self.paused.discard(task) - self.io_release_task(task) - task.throw(TooSlowError(task)) + self.paused.discard(task) + self.io_release_task(task) + task.throw(TooSlowError(task)) def schedule_tasks(self, tasks: List[Task]): """ @@ -446,8 +446,9 @@ class AsyncScheduler: # This is to ensure that even when tasks are # awaited instead of spawned, timeouts work as # expected - if t.done() or t in self.run_ready or t is self.current_task: + if t.done() or t in self.run_ready: self.paused.discard(t) + print(t is self.current_task) while self.paused and self.paused.get_closest_deadline() <= self.clock(): # Reschedules tasks when their deadline has elapsed task = self.paused.get() @@ -598,7 +599,7 @@ class AsyncScheduler: """ if task.pool and task.pool.enclosed_pool and not task.pool.enclosed_pool.done(): - return + return for t in task.joiners: if t not in self.run_ready: # Since a task can be the parent diff --git a/giambio/exceptions.py b/giambio/exceptions.py index 2623d89..8d1c56e 100644 --- a/giambio/exceptions.py +++ b/giambio/exceptions.py @@ -59,6 +59,7 @@ class ResourceClosed(GiambioError): Raised when I/O is attempted on a closed resource """ + class TooSlowError(GiambioError): """ This is raised if the timeout of a pool created using diff --git a/giambio/run.py b/giambio/run.py index dad98e5..bf14e28 100644 --- a/giambio/run.py +++ b/giambio/run.py @@ -127,4 +127,3 @@ def skip_after(timeout: int or float): loop.current_task.next_deadline = mgr.timeout or 0.0 loop.deadlines.put(mgr) return mgr - diff --git a/giambio/sync.py b/giambio/sync.py index 0a385e0..99764f3 100644 --- a/giambio/sync.py +++ b/giambio/sync.py @@ -63,4 +63,5 @@ class Queue: self.events = {} + # async def put diff --git a/tests/timeout.py b/tests/timeout.py index 5d31d3f..515dd4c 100644 --- a/tests/timeout.py +++ b/tests/timeout.py @@ -11,9 +11,11 @@ async def child(name: int): async def main(): start = giambio.clock() try: - async with giambio.with_timeout(10) as pool: + async with giambio.with_timeout(12) as pool: await pool.spawn(child, 7) # This will complete - await pool.spawn(child, 15) # This will not + 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 except giambio.exceptions.TooSlowError: print("[main] One or more children have timed out!") @@ -21,4 +23,4 @@ async def main(): if __name__ == "__main__": - giambio.run(main, debugger=()) + giambio.run(main, debugger=Debugger()) diff --git a/tests/timeout2.py b/tests/timeout2.py index 48d18c5..42d75fe 100644 --- a/tests/timeout2.py +++ b/tests/timeout2.py @@ -12,7 +12,9 @@ async def main(): start = giambio.clock() async with giambio.skip_after(10) as pool: await pool.spawn(child, 7) # This will complete - await pool.spawn(child, 15) # This will not + 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 if pool.timed_out: print("[main] One or more children have timed out!")