bpo-34066: Disabled interruption before SETUP_WITH and BEFORE_ASYNC_WITH. (GH-8159)

This will prevent emitting a resource warning when the execution was
interrupted by Ctrl-C between calling open() and entering a 'with' block
in "with open()".
This commit is contained in:
Serhiy Storchaka 2018-07-09 15:40:14 +03:00 committed by Nick Coghlan
parent cf7303ed2a
commit 3f4d90d4d7
2 changed files with 13 additions and 4 deletions

View File

@ -0,0 +1,2 @@
Disabled interruption by Ctrl-C between calling ``open()`` and entering a
**with** block in ``with open()``.

View File

@ -928,11 +928,18 @@ main_loop:
Py_MakePendingCalls() above. */ Py_MakePendingCalls() above. */
if (_Py_atomic_load_relaxed(&_PyRuntime.ceval.eval_breaker)) { if (_Py_atomic_load_relaxed(&_PyRuntime.ceval.eval_breaker)) {
if (_Py_OPCODE(*next_instr) == SETUP_FINALLY || opcode = _Py_OPCODE(*next_instr);
_Py_OPCODE(*next_instr) == YIELD_FROM) { if (opcode == SETUP_FINALLY ||
/* Two cases where we skip running signal handlers and other opcode == SETUP_WITH ||
opcode == BEFORE_ASYNC_WITH ||
opcode == YIELD_FROM) {
/* Few cases where we skip running signal handlers and other
pending calls: 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 *very* useful, but might help in some cases and it's
traditional) traditional)
- If we're resuming a chain of nested 'yield from' or - If we're resuming a chain of nested 'yield from' or