From a94cdea31f85928f2afb061859ca6b345bbd2061 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 16 Aug 2024 15:52:58 -0400 Subject: [PATCH] add get_running_loop(); remove ThreadSafeFlag --- asyncio/core.py | 13 +++++++++++++ asyncio/event.py | 30 +----------------------------- 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/asyncio/core.py b/asyncio/core.py index eaeef81..8a4eb1d 100644 --- a/asyncio/core.py +++ b/asyncio/core.py @@ -446,6 +446,19 @@ def get_event_loop(runq_len=0, waitq_len=0): return Loop +# CIRCUITPY-CHANGE: added, to match CPython +def get_running_loop(): + """Return the event loop used to schedule and run tasks. See `Loop`.""" + + return Loop + + +def get_event_loop(runq_len=0, waitq_len=0): + # CIRCUITPY-CHANGE: doc + """Return the event loop used to schedule and run tasks. See `Loop`. Deprecated and will be removed later.""" + + # CIRCUITPY-CHANGE + return get_running_loop() def current_task(): # CIRCUITPY-CHANGE: doc diff --git a/asyncio/event.py b/asyncio/event.py index 362d2e1..af81afc 100644 --- a/asyncio/event.py +++ b/asyncio/event.py @@ -72,32 +72,4 @@ async def wait(self): return True -# MicroPython-extension: This can be set from outside the asyncio event loop, -# such as other threads, IRQs or scheduler context. Implementation is a stream -# that asyncio will poll until a flag is set. -# Note: Unlike Event, this is self-clearing after a wait(). -try: - import io - - class ThreadSafeFlag(io.IOBase): - def __init__(self): - self.state = 0 - - def ioctl(self, req, flags): - if req == 3: # MP_STREAM_POLL - return self.state * flags - return -1 # Other requests are unsupported - - def set(self): - self.state = 1 - - def clear(self): - self.state = 0 - - async def wait(self): - if not self.state: - yield core._io_queue.queue_read(self) - self.state = 0 - -except ImportError: - pass +# CIRCUITPY: remove ThreadSafeFlag