summaryrefslogtreecommitdiffstatshomepage
path: root/extmod/asyncio
Commit message (Collapse)AuthorAge
* extmod/asyncio: Fix early exit of asyncio scheduler.Yoctopuce dev2025-05-07
| | | | | | | | | | | | | | | | | | | | | This commit fixes three open issues related to the asyncio scheduler exiting prematurely when the main task queue is empty, in cases where CPython would not exit (for example, because the main task is not done because it's on a different queue). In the first case, the scheduler exits because running a task via `run_until_complete` did not schedule any dependent tasks. In the other two cases, the scheduler exits because the tasks are queued in an event queue. Tests have been added which reproduce the original issues. These test cases document the unauthorized use of `Event.set()` from a soft IRQ, and are skipped in unsupported environments (webassembly and native emitter). Fixes issues #16759, #16569 and #16318. Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
* extmod/asyncio: Make current_task raise exception when there is no task.Damien George2024-02-28
| | | | | | | | Matches CPython behaviour. Fixes issue #11530. Signed-off-by: Damien George <damien@micropython.org>
* extmod/asyncio: Support gather of tasks that finish early.Damien George2024-01-22
| | | | | | | Adds support to asyncio.gather() for the case that one or more (or all) sub-tasks finish and/or raise an exception before the gather starts. Signed-off-by: Damien George <damien@micropython.org>
* extmod/asyncio: Remove non-working Stream __aenter__/__aexit__ methods.Damien George2023-12-20
| | | | | | | | | It looks like these never worked and there are no tests for this functionality. Furthermore, CPython doesn't support this. Fixes #12995. Signed-off-by: Damien George <damien@micropython.org>
* extmod/asyncio: Add ssl support with SSLContext.Carlosgg2023-12-14
| | | | | | | | | | | | | | This adds asyncio ssl support with SSLContext and the corresponding tests in `tests/net_inet` and `tests/multi_net`. Note that not doing the handshake on connect will delegate the handshake to the following `mbedtls_ssl_read/write` calls. However if the handshake fails when a client certificate is required and not presented by the peer, it needs to be notified of this handshake error (otherwise it will hang until timeout if any). Finally at MicroPython side raise the proper mbedtls error code and message. Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
* extmod/asyncio: Emit errors to stderr, not stdout.Matthias Urlichs2023-10-13
| | | | | | | | | | Sometimes these are different file descriptors, not to mention the Unix port, so use stderr to distinguish these error messages. CPython prints to stdout, but it does it via a call to the logging module. We don't want to introduce a dependency on logging, so printing to stderr is a good alternative. One can override default_exception_handler() if needed.
* extmod/asyncio/stream.py: Fix cancellation handling of start_server.Jim Mussared2023-10-02
| | | | | | | | | | | | | | | | | | | The following code: server = await asyncio.start_server(...) async with server: ... code that raises ... would lose the original exception because the server's task would not have had a chance to be scheduled yet, and so awaiting the task in wait_closed would raise the cancellation instead of the original exception. Additionally, ensures that explicitly cancelling the parent task delivers the cancellation correctly (previously was masked by the server loop), now this only happens if the server was closed, not when the task was cancelled. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* extmod/asyncio/event.py: Fix ThreadSafeFlag.ioctl return.Jim Mussared2023-09-29
| | | | | | | | | | | | | | | | | | | | iobase_ioctl expects that an ioctl method must return an integer, and will raise otherwise. This was tripping up aioble on Unix, where the new hybrid modselect.c implementation will attempt to extract a file descriptor from the pollable via ioctl(MP_STREAM_GET_FILENO). However, ThreadSafeFlag's ioctl only supported MP_STREAM_POLL, and returned None otherwise. This makes it return `-1` (to match tests/extmod/select_poll_custom.py). It should probably be `-22` (corresponding to MP_EINVAL), but the value is never checked, and MP_EINVAL can be a different value on different ports. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* extmod/asyncio/uasyncio.py: Add backwards-compatible uasyncio alias.Jim Mussared2023-06-19
| | | | | | | | | | | | This allows existing code that does `import uasyncio` or `import uasyncio as asyncio` to continue working. It uses the same lazy-loading as asyncio to prevent loading of unused features. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* extmod/asyncio: Rename uasyncio to asyncio.Jim Mussared2023-06-19
The asyncio module now has much better CPython compatibility and deserves to be just called "asyncio". This will avoid people having to write `from uasyncio import asyncio`. Renames all files, and updates port manifests to use the new path. Also renames the built-in _uasyncio to _asyncio. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>