summaryrefslogtreecommitdiffstatshomepage
path: root/extmod/uasyncio/core.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2020-04-09 13:15:47 +1000
committerDamien George <damien.p.george@gmail.com>2020-04-13 22:16:52 +1000
commitdb137e70dcf67de26828e17c2d3dc9d21e971eb0 (patch)
treeb6e5e8cd0b2f63ed169379a33c3021c156008148 /extmod/uasyncio/core.py
parent1bbc15dd15b232f833b6cc2066bd9ca2b7fe6b66 (diff)
downloadmicropython-db137e70dcf67de26828e17c2d3dc9d21e971eb0.tar.gz
micropython-db137e70dcf67de26828e17c2d3dc9d21e971eb0.zip
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.
Diffstat (limited to 'extmod/uasyncio/core.py')
-rw-r--r--extmod/uasyncio/core.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/extmod/uasyncio/core.py b/extmod/uasyncio/core.py
index e2f64119c5..689487d36a 100644
--- a/extmod/uasyncio/core.py
+++ b/extmod/uasyncio/core.py
@@ -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()