extmod/uasyncio: Add Loop.new_event_loop method.

This commit adds Loop.new_event_loop() which is used to reset the singleton
event loop.  This functionality is put here instead of in Loop.close() to
make it possible to write code that is compatible with CPython.
This commit is contained in:
Damien George
2020-04-09 13:15:47 +10:00
parent 1bbc15dd15
commit db137e70dc
4 changed files with 62 additions and 7 deletions

View File

@@ -132,13 +132,6 @@ class IOQueue:
################################################################################
# Main run loop
# TaskQueue of Task instances
_task_queue = TaskQueue()
# Task queue and poller for stream IO
_io_queue = IOQueue()
# Ensure the awaitable is a task
def _promote_to_task(aw):
return aw if isinstance(aw, Task) else create_task(aw)
@@ -269,3 +262,16 @@ class Loop:
# The runq_len and waitq_len arguments are for legacy uasyncio compatibility
def get_event_loop(runq_len=0, waitq_len=0):
return Loop
def new_event_loop():
global _task_queue, _io_queue
# TaskQueue of Task instances
_task_queue = TaskQueue()
# Task queue and poller for stream IO
_io_queue = IOQueue()
return Loop
# Initialise default event loop
new_event_loop()