diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-07-07-20-15-34.bpo-34066.y9vs6s.rst b/Misc/NEWS.d/next/Core and Builtins/2018-07-07-20-15-34.bpo-34066.y9vs6s.rst new file mode 100644 index 00000000000..b12afad8da8 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2018-07-07-20-15-34.bpo-34066.y9vs6s.rst @@ -0,0 +1,2 @@ +Disabled interruption by Ctrl-C between calling ``open()`` and entering a +**with** block in ``with open()``. diff --git a/Python/ceval.c b/Python/ceval.c index 422a29ed77d..90ad591dcd8 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -928,11 +928,18 @@ main_loop: Py_MakePendingCalls() above. */ if (_Py_atomic_load_relaxed(&_PyRuntime.ceval.eval_breaker)) { - if (_Py_OPCODE(*next_instr) == SETUP_FINALLY || - _Py_OPCODE(*next_instr) == YIELD_FROM) { - /* Two cases where we skip running signal handlers and other + opcode = _Py_OPCODE(*next_instr); + if (opcode == SETUP_FINALLY || + opcode == SETUP_WITH || + opcode == BEFORE_ASYNC_WITH || + opcode == YIELD_FROM) { + /* Few cases where we skip running signal handlers and other pending calls: - - If we're about to enter the try: of a try/finally (not + - If we're about to enter the 'with:'. It will prevent + emitting a resource warning in the common idiom + 'with open(path) as file:'. + - If we're about to enter the 'async with:'. + - If we're about to enter the 'try:' of a try/finally (not *very* useful, but might help in some cases and it's traditional) - If we're resuming a chain of nested 'yield from' or