From 941464437d24253ec55abe2584db29ef38b6ac6b Mon Sep 17 00:00:00 2001 From: nocturn9x Date: Thu, 22 Apr 2021 12:02:40 +0200 Subject: [PATCH] Some changes and fixes to exceptions behavior --- giambio/core.py | 7 +++++++ tests/nested_exception.py | 6 ++---- tests/server.py | 5 ++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/giambio/core.py b/giambio/core.py index d725798..0326dfc 100644 --- a/giambio/core.py +++ b/giambio/core.py @@ -504,6 +504,13 @@ class AsyncScheduler: # pool have finished executing, either # by cancellation, an exception # or just returned + for t in task.joiners: + # Propagate the exception + try: + t.throw(task.exc) + except StopIteration: + # TODO: Need anything else? + task.joiners.remove(t) self.reschedule_joiners(task) def sleep(self, seconds: int or float): diff --git a/tests/nested_exception.py b/tests/nested_exception.py index 2d21b09..28f299f 100644 --- a/tests/nested_exception.py +++ b/tests/nested_exception.py @@ -35,10 +35,8 @@ async def main(): pool.spawn(child1) print("[main] Children spawned, awaiting completion") async with giambio.create_pool() as new_pool: - # This pool won't be affected from exceptions - # in outer pools. This is a guarantee that giambio - # ensures: an exception will only be propagated - # after all enclosed task pools have exited + # This pool will be cancelled by the exception + # in the other pool new_pool.spawn(child2) new_pool.spawn(child3) print("[main] 3rd child spawned") diff --git a/tests/server.py b/tests/server.py index 91a58b8..ad4b79c 100644 --- a/tests/server.py +++ b/tests/server.py @@ -50,7 +50,7 @@ async def handler(sock: AsyncSocket, client_address: tuple): break elif data == b"exit\n": await sock.send_all(b"I'm dead dude\n") - raise TypeError("Oh, no, I'm gonna die!") + raise TypeError("Oh, no, I'm gonna die!") # This kills the entire application! logging.info(f"Got: {data!r} from {address}") await sock.send_all(b"Got: " + data) logging.info(f"Echoed back {data!r} to {address}") @@ -58,7 +58,7 @@ async def handler(sock: AsyncSocket, client_address: tuple): if __name__ == "__main__": - port = int(sys.argv[1]) if len(sys.argv) > 1 else 1500 + port = int(sys.argv[1]) if len(sys.argv) > 1 else 1501 logging.basicConfig(level=20, format="[%(levelname)s] %(asctime)s %(message)s", datefmt="%d/%m/%Y %p") try: giambio.run(serve, ("localhost", port), debugger=None) @@ -67,4 +67,3 @@ if __name__ == "__main__": logging.info("Ctrl+C detected, exiting") else: logging.error(f"Exiting due to a {type(error).__name__}: {error}") - raise