Skip to content

Commit

Permalink
add get_running_loop(); remove ThreadSafeFlag
Browse files Browse the repository at this point in the history
  • Loading branch information
dhalbert committed Aug 16, 2024
1 parent b544f2f commit a94cdea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 29 deletions.
13 changes: 13 additions & 0 deletions asyncio/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 1 addition & 29 deletions asyncio/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a94cdea

Please sign in to comment.