QUERY · ISSUE
extmod/uasyncio: add serve_forever()?
extmod
Official example from python documentation:
async def main():
# Get a reference to the event loop as we plan to use
# low-level APIs.
loop = asyncio.get_running_loop()
server = await loop.create_server(
lambda: EchoServerProtocol(),
'127.0.0.1', 8888)
async with server:
await server.serve_forever()
asyncio.run(main())
Micropython's Server class already has support for async with, but lacks convenient method serve_forever.
Do you think it is make sense to add it?
CANDIDATE · PULL REQUEST
uasyncio/stream.py: Handle cancellation before server start.
extmod
Originally reported here: https://forum.micropython.org/viewtopic.php?f=20&t=12678&p=68845#p68791
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.
In this case the code that raised was calling server.serve_forever() which we don't support.