From 24cb49b3c9e6190f56330b7b0967932f16e3d336 2020-01-21 08:02:21 From: yangyang Date: 2020-01-21 08:02:21 Subject: [PATCH] catch `MemoryError` in compiling --- diff --git a/IPython/core/async_helpers.py b/IPython/core/async_helpers.py index 1a7d889..fb4cc19 100644 --- a/IPython/core/async_helpers.py +++ b/IPython/core/async_helpers.py @@ -146,20 +146,20 @@ def _should_be_async(cell: str) -> bool: If it works, assume it should be async. Otherwise Return False. - Not handled yet: If the block of code has a return statement as the top + Not handled yet: If the block of code has a return statement as the top level, it will be seen as async. This is a know limitation. """ if sys.version_info > (3, 8): try: code = compile(cell, "<>", "exec", flags=getattr(ast,'PyCF_ALLOW_TOP_LEVEL_AWAIT', 0x0)) return inspect.CO_COROUTINE & code.co_flags == inspect.CO_COROUTINE - except SyntaxError: + except (SyntaxError, MemoryError): return False try: # we can't limit ourself to ast.parse, as it __accepts__ to parse on # 3.7+, but just does not _compile_ code = compile(cell, "<>", "exec") - except SyntaxError: + except (SyntaxError, MemoryError): try: parse_tree = _async_parse_cell(cell) @@ -167,7 +167,7 @@ def _should_be_async(cell: str) -> bool: v = _AsyncSyntaxErrorVisitor() v.visit(parse_tree) - except SyntaxError: + except (SyntaxError, MemoryError): return False return True return False