From 68df239020571adb177c8979c3b31ed3663fe8d2 Mon Sep 17 00:00:00 2001 From: nocturn9x Date: Wed, 25 Mar 2020 12:04:57 +0100 Subject: [PATCH] Fixed to the cancel method --- experiment.py | 5 +++-- giambio/core.py | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/experiment.py b/experiment.py index 8c3b8d3..c2cade5 100644 --- a/experiment.py +++ b/experiment.py @@ -44,12 +44,13 @@ async def count(stop, step=1): async def main(): print("Spawning countdown immediately, scheduling count for 4 secs from now") task = loop.spawn(countdown(8)) - task1 = loop.schedule(count(8, 2), 4) # Schedules the task, it will be ran 4 seconds from now + task1 = loop.schedule(count(6, 2), 4) # Schedules the task, it will be ran 4 seconds from now await giambio.sleep(0) # TODO: Fix this to avoid the need to use a checkpoint before cancelling await task.cancel() # result = await task.join() # Would raise TaskError! + result = 'Task cancelled' if task.cancelled else task.result.val result1 = await task1.join() - print(f"countdown returned: {None}\ncount returned: {result1}") + print(f"countdown returned: {result}\ncount returned: {result1}") print("All done") loop.start(main) diff --git a/giambio/core.py b/giambio/core.py index d8b6a2a..b84178b 100644 --- a/giambio/core.py +++ b/giambio/core.py @@ -54,7 +54,6 @@ class EventLoop: self.to_run.extend(self.joined.pop(self.running, ())) # Reschedules the parent task except RuntimeError: self.to_run.extend(self.joined.pop(self.running, ())) # Reschedules the parent task - self.to_run.append(self.running) except Exception as has_raised: self.to_run.extend(self.joined.pop(self.running, ())) # Reschedules the parent task if self.running.joined: # Let the join function handle the hassle of propagating the error