[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
self.assertEqual(messages, [])
def test_unhandled_exceptions(self) -> None: def _basetest_unhandled_exceptions(self, handle_echo): port = socket_helper.find_unused_port()
messages = []
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()
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__':