CancelledError in uasyncio/stream.py in _serve when calling server.wait_closed() #11410
Replies: 3 comments 2 replies
-
Did the same code work on an earlier build? |
Beta Was this translation helpful? Give feedback.
-
Looking at the def close(self):
self.task.cancel()
async def wait_closed(self):
await self.task I don't think there's any need to issue async def foo():
server.close()
await asyncio.sleep(0)
# It's closed now |
Beta Was this translation helpful? Give feedback.
-
Not sure why you get a CancelledError being thrown in stream.py _serve when the CancelledError is supposed to be caught: import uasyncio as asyncio
async def handle(r,w):
pass
async def main():
loop = asyncio.new_event_loop()
server = await asyncio.start_server(handle, '0.0.0.0', 80)
server.close()
await server.wait_closed()
loop.run_forever()
asyncio.run(main())
'''
Traceback (most recent call last):
File "<stdin>", line 13, in <module>
File "uasyncio/core.py", line 1, in run
File "uasyncio/core.py", line 1, in run_until_complete
File "uasyncio/core.py", line 1, in run_until_complete
File "<stdin>", line 10, in main
File "uasyncio/stream.py", line 1, in wait_closed
File "uasyncio/core.py", line 1, in run_until_complete
File "uasyncio/stream.py", line 1, in _serve
CancelledError: ''' micropython/extmod/uasyncio/stream.py Lines 135 to 151 in 786013d |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I migrated to MicroPython v1.20.0 on 2023-04-26; Raspberry Pi Pico W with RP2040.
I'm getting an unhandled CancelledError when calling server.close followed by await server.wait_closed on the server object returned from await asyncio.start_server.
File "uasyncio/stream.py", line 1, in wait_closed
File "uasyncio/core.py", line 1, in run_until_complete
File "uasyncio/stream.py", line 1, in _serve
I've set an exception handler on the loop which doesn't catch this CancelledError. Once this error is thrown all sockets created outside of start_server also become unresponsive, even if I wrap wait_closed in try/except.
Beta Was this translation helpful? Give feedback.
All reactions