◐ Shell
clean mode source ↗

[3.12] gh-113538: Don't error in stream reader protocol callback when task is cancelled (GH-113690) by miss-islington · Pull Request #113713 · python/cpython

Expand Up @@ -1129,7 +1129,7 @@ async def inner(httpd):
self.assertEqual(messages, [])
def test_unhandled_exceptions(self) -> None: def _basetest_unhandled_exceptions(self, handle_echo): port = socket_helper.find_unused_port()
messages = [] Expand All @@ -1143,9 +1143,6 @@ async def client(): 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() Expand All @@ -1154,11 +1151,20 @@ async def handle_echo(reader, writer): await server.wait_closed()
self.loop.run_until_complete(main()) return messages
def test_unhandled_exception(self): async def handle_echo(reader, writer): raise Exception('test') messages = self._basetest_unhandled_exceptions(handle_echo) self.assertEqual(messages[0]['message'], 'Unhandled exception in client_connected_cb') # Break explicitly reference cycle messages = None 'Unhandled exception in client_connected_cb')
def test_unhandled_cancel(self): async def handle_echo(reader, writer): asyncio.current_task().cancel() messages = self._basetest_unhandled_exceptions(handle_echo) self.assertEqual(messages, [])

if __name__ == '__main__': Expand Down