From afa61925018dfacb7e031fc395c21ea857c2d00e Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 3 Dec 2017 00:22:17 +0200 Subject: [PATCH] uasyncio.core: Store currently executed task as an attribute of event loop. Currently executed task is a top-level coroutine scheduled in the event loop (note that sub-coroutines aren't scheduled in the event loop and are executed implicitly by yield from/await, driven by top-level coro). --- uasyncio.core/uasyncio/core.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/uasyncio.core/uasyncio/core.py b/uasyncio.core/uasyncio/core.py index 634f41cf..f45daf0d 100644 --- a/uasyncio.core/uasyncio/core.py +++ b/uasyncio.core/uasyncio/core.py @@ -19,6 +19,10 @@ class EventLoop: def __init__(self, len=42): self.q = utimeq.utimeq(len) + # Current task being run. Task is a top-level coroutine scheduled + # in the event loop (sub-coroutines executed transparently by + # yield from/await, event loop "doesn't see" them). + self.cur_task = None def time(self): return time.ticks_ms() @@ -72,6 +76,7 @@ class EventLoop: args = cur_task[2] if __debug__ and DEBUG: log.debug("Next coroutine to run: %s", (t, cb, args)) + self.cur_task = cb # __main__.mem_info() else: self.wait(-1)