diff options
author | Damien George <damien@micropython.org> | 2024-02-26 10:52:12 +1100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2024-02-28 15:48:51 +1100 |
commit | 8692d2602a7775fea22d75ebf5b50971dc2b968f (patch) | |
tree | fe844a4c454c261adf0c7d25e30b25817e9d475f /extmod/asyncio/core.py | |
parent | 8fdcc25eb07731a64077b7576c5d477cf81e2dd5 (diff) | |
download | micropython-8692d2602a7775fea22d75ebf5b50971dc2b968f.tar.gz micropython-8692d2602a7775fea22d75ebf5b50971dc2b968f.zip |
extmod/asyncio: Make current_task raise exception when there is no task.
Matches CPython behaviour.
Fixes issue #11530.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'extmod/asyncio/core.py')
-rw-r--r-- | extmod/asyncio/core.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/extmod/asyncio/core.py b/extmod/asyncio/core.py index e5af3038f7..8aad234514 100644 --- a/extmod/asyncio/core.py +++ b/extmod/asyncio/core.py @@ -164,6 +164,7 @@ def run_until_complete(main_task=None): dt = max(0, ticks_diff(t.ph_key, ticks())) elif not _io_queue.map: # No tasks can be woken so finished running + cur_task = None return # print('(poll {})'.format(dt), len(_io_queue.map)) _io_queue.wait_io_event(dt) @@ -188,6 +189,7 @@ def run_until_complete(main_task=None): assert t.data is None # This task is done, check if it's the main task and then loop should stop if t is main_task: + cur_task = None if isinstance(er, StopIteration): return er.value raise er @@ -242,6 +244,7 @@ async def _stopper(): pass +cur_task = None _stop_task = None @@ -291,6 +294,8 @@ def get_event_loop(runq_len=0, waitq_len=0): def current_task(): + if cur_task is None: + raise RuntimeError("no running event loop") return cur_task |