Now exceptions sort of work

This commit is contained in:
nocturn9x 2020-11-12 22:45:00 +01:00
parent 5ff8d4a06e
commit 8b095fbf72
2 changed files with 28 additions and 35 deletions

View File

@ -62,6 +62,7 @@ class AsyncScheduler:
the loop's functionality only trough some fixed entry points, which in turn yield and
give execution control to the loop itself."""
try:
while True:
if not self.selector.get_map() and not any(
[self.paused, self.tasks, self.event_waiting]
@ -71,22 +72,13 @@ class AsyncScheduler:
if (
self.paused
): # If there are no actively running tasks, we try to schedule the asleep ones
try:
self.check_sleeping()
except BaseException as error:
self.current_task.exc = error
self.reschedule_parent(self.current_task)
if self.selector.get_map():
try:
self.check_io()
except BaseException as error:
self.current_task.exc = error
self.reschedule_parent(self.current_task)
while self.tasks: # While there are tasks to run
self.current_task = (
self.tasks.popleft()
) # Sets the currently running task
try:
if self.current_task.status == "cancel": # Deferred cancellation
self.current_task.cancelled = True
self.current_task.throw(CancelledError(self.current_task))
@ -109,6 +101,7 @@ class AsyncScheduler:
except BaseException as error: # Coroutine raised
self.current_task.exc = error
self.reschedule_parent(self.current_task)
self.join(self.current_task)
def check_events(self):
"""Checks for ready or expired events and triggers them"""

View File

@ -41,5 +41,5 @@ async def echo_handler(sock: AsyncSocket, addr: tuple):
if __name__ == "__main__":
try:
sched.start(server(("", 25001)))
except KeyboardInterrupt: # Exceptions propagate!
print("Exiting...")
except giambio.exceptions.GiambioError as wrapper: # Exceptions propagate!
print(f"Exiting due to a {type(wrapper.__cause__).__name__}")