mirror of https://github.com/nocturn9x/giambio.git
Some changes and fixes to exceptions behavior
This commit is contained in:
parent
dcd3cae674
commit
941464437d
|
@ -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):
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue