mirror of
https://github.com/python/cpython.git
synced 2025-10-05 06:31:48 +00:00
[3.12] GH-110894: Call loop exception handler for exceptions in client_connected_cb (GH-111601) (#111632)
Call loop exception handler for exceptions in `client_connected_cb` of `asyncio.start_server` so that applications can handle it..
(cherry picked from commit 229f44d353
)
This commit is contained in:
parent
99f0dd88b1
commit
9aa88290d8
3 changed files with 42 additions and 0 deletions
|
@ -1074,6 +1074,35 @@ os.close(fd)
|
|||
|
||||
self.assertEqual(messages, [])
|
||||
|
||||
def test_unhandled_exceptions(self) -> None:
|
||||
port = socket_helper.find_unused_port()
|
||||
|
||||
messages = []
|
||||
self.loop.set_exception_handler(lambda loop, ctx: messages.append(ctx))
|
||||
|
||||
async def client():
|
||||
rd, wr = await asyncio.open_connection('localhost', port)
|
||||
wr.write(b'test msg')
|
||||
await wr.drain()
|
||||
wr.close()
|
||||
await wr.wait_closed()
|
||||
|
||||
async def main():
|
||||
async def handle_echo(reader, writer):
|
||||
raise Exception('test')
|
||||
|
||||
server = await asyncio.start_server(
|
||||
handle_echo, 'localhost', port)
|
||||
await server.start_serving()
|
||||
await client()
|
||||
server.close()
|
||||
await server.wait_closed()
|
||||
|
||||
self.loop.run_until_complete(main())
|
||||
|
||||
self.assertEqual(messages[0]['message'],
|
||||
'Unhandled exception in client_connected_cb')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue