From 07dd63dd4991cc7a5be0cd90edb28c2d060f0ac7 Mon Sep 17 00:00:00 2001 From: nocturn9x Date: Wed, 10 May 2023 21:48:15 +0200 Subject: [PATCH] More fixes to Ctrl+C --- aiosched/kernel.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/aiosched/kernel.py b/aiosched/kernel.py index b94ca06..9a00b5d 100644 --- a/aiosched/kernel.py +++ b/aiosched/kernel.py @@ -365,6 +365,7 @@ class FIFOKernel: self.debugger.before_task_step(self.current_task) if self._sigint_handled: self._sigint_handled = False + self.current_task.throw(KeyboardInterrupt()) _runner = partial(self.current_task.throw, KeyboardInterrupt) _data = [] # Run a single step with the calculation (i.e. until a yield @@ -431,6 +432,15 @@ class FIFOKernel: # (no matter what it's doing, because it doesn't really # matter) and let run_task_step raise an exception inside # it + + # P.S.: Okay, so, I never liked this code here because it + # is really hard to test properly in different contexts: while + # it's true that it's technically okay for us to raise KeyboardInterrupt + # anywhere in the user's code, simplifying the critical path and making it + # behave more predictably has priority. Also, if trio can afford to be lazy, + # then so can we. Besides, the loop's entry point _is_ technically part of + # where KeyboardInterrupt is allowed to pop up + """ task: Task | None = None if self.selector.get_map(): # Pretty convoluted, huh? Sorry, but I wanted this on one line ;) @@ -439,6 +449,8 @@ class FIFOKernel: task, *_ = self.paused.get() else: task = self.current_task + """ + task = self.entry_point self.run_ready.appendleft(task) self.handle_errors(self.run_task_step) elif not self.run_ready: