← index #5858PR #5332
Related · high · value 1.075
QUERY · ISSUE

extmod/uasyncio Please provide CPython's synchronisation primitives

openby peterhinchopened 2020-04-02updated 2023-07-16
extmod

CPython provides Queue, Semaphore, BoundedSemaphore and Condition in addition to the provided Lock and Event classes.

In the case of Queue the issue was raised in https://github.com/micropython/micropython/issues/5828.

CANDIDATE · PULL REQUEST

extmod: add new implementation of uasyncio

mergedby dpgeorgeopened 2019-11-15updated 2020-03-25
extmod

This PR adds a completely new implementation of the uasyncio module. The aim of this version (compared to the original one in micropython-lib) is to be more compatible with CPython's asyncio module, so that one can more easily write code that runs under both MicroPython and CPython (and reuse CPython asyncio libraries, follow CPython asyncio tutorials, etc). Async code is not easy to write and any knowledge users already have from CPython asyncio should transfer to uasyncio without effort, and vice versa.

The implementation here attempts to provide good compatibility with CPython's asyncio while still being "micro" enough to run where MicroPython runs. This follows the general philosophy of MicroPython itself, to make it feel like Python.

The existing uasyncio at micropython-lib has its merits and will remain as an independent module/library, but would need to be renamed so as to not clash with the new implementation here. Note that the implementation in this PR provides a compatibility layer to be compatible (for the most part) with the original uasyncio.

It's currently implemented in pure Python and runs under existing, unmodified MicroPython (there's a commit in this PR to improve allocation of iterator buffers but that is not needed for uasyncio to work). In the future parts of this implementation could be moved to C to improve speed and reduce memory usage. But it would be good to maintain a pure-Python version as a reference version.

At this point efficiency is not a goal, rather correctness is. Tests are included in this PR.

Thanks to @peterhinch and @kevinkk525 for help with initial testing and bug finding.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied