summaryrefslogtreecommitdiff
path: root/extmod/uasyncio
AgeCommit message (Collapse)Author
2020-08-22extmod/uasyncio: Truncate negative sleeps to 0.Damien George
Otherwise a task that continuously awaits on a large negative sleep can monopolise the scheduler (because its wake time is always less than everything else in the pairing heap). Signed-off-by: Damien George <damien@micropython.org>
2020-07-25extmod/uasyncio: Add StreamReader.readexactly(n) method.Damien George
It raises on EOFError instead of an IncompleteReadError (which is what CPython does). But the latter is derived from EOFError so code compatible with MicroPython and CPython can be written by catching EOFError (eg see included test). Fixes issue #6156. Signed-off-by: Damien George <damien@micropython.org>
2020-06-10extmod/uasyncio: Add asyncio.wait_for_ms function.Damien George
Fixes issue #6107.
2020-04-14extmod/uasyncio: Change cannot to can't in error message, and test exp.Damien George
Follow up to 8e048d2548867aac743866ca5a4c244b7b5aac09 which missed these.
2020-04-13extmod/uasyncio: Add Loop.new_event_loop method.Damien George
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.
2020-04-04extmod/uasyncio: Add global exception handling methods.Kevin Köck
This commit adds support for global exception handling in uasyncio according to the CPython error handling: https://docs.python.org/3/library/asyncio-eventloop.html#error-handling-api This allows a program to receive exceptions from detached tasks and log them to an appropriate location, instead of them being printed to the REPL. The implementation preallocates a context dictionary so in case of an exception there shouldn't be any RAM allocation. The approach here is compatible with CPython except that in CPython the exception handler is called once the task that threw an uncaught exception is freed, whereas in MicroPython the exception handler is called immediately when the exception is thrown.
2020-04-02extmod/uasyncio: Add StreamReader/StreamWriter as aliases of Stream cls.Damien George
To be compatible with CPython. Fixes issue #5847.
2020-04-02extmod/uasyncio: Add error message to Lock.release's RuntimeError.Kevin Köck
Otherwise it can be hard to understand what the error is if a blank RuntimeError is raised.
2020-04-02extmod/uasyncio: Implement Loop.stop() to stop the event loop.Damien George
2020-04-01extmod/uasyncio: Don't create a Loop instance in get_event_loop().Damien George
The event loop is (for now) just a singleton so make it so that Loop instances are not needed.
2020-03-26extmod/uasyncio: Add manifest.py for freezing uasyncio Py files.Damien George
2020-03-26extmod/uasyncio: Add optional implementation of core uasyncio in C.Damien George
Implements Task and TaskQueue classes in C, using a pairing-heap data structure. Using this reduces RAM use of each Task, and improves overall performance of the uasyncio scheduler.
2020-03-26extmod/uasyncio: Add new implementation of uasyncio module.Damien George
This commit 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 main change is to use a Task object for each coroutine. This allows more flexibility to queue tasks in various places, eg the main run loop, tasks waiting on events, locks or other tasks. It no longer requires pre-allocating a fixed queue size for the main run loop. A pairing heap is used to queue Tasks. It's currently implemented in pure Python, separated into components with lazy importing for optional components. In the future parts of this implementation can be moved to C to improve speed and reduce memory usage. But the aim is to maintain a pure-Python version as a reference version.