[3.6] bpo-34066: Disabled interruption before SETUP_WITH and BEFORE_A… · python/cpython@eeaae26

File tree

2 files changed

lines changed

  • Misc/NEWS.d/next/Core and Builtins

2 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -0,0 +1,2 @@

1+

Disabled interruption by Ctrl-C between calling ``open()`` and entering a

2+

**with** block in ``with open()``.

Original file line numberDiff line numberDiff line change

@@ -1155,11 +1155,18 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)

11551155

Py_MakePendingCalls() above. */

11561156
11571157

if (_Py_atomic_load_relaxed(&eval_breaker)) {

1158-

if (_Py_OPCODE(*next_instr) == SETUP_FINALLY ||

1159-

_Py_OPCODE(*next_instr) == YIELD_FROM) {

1160-

/* Two cases where we skip running signal handlers and other

1158+

opcode = _Py_OPCODE(*next_instr);

1159+

if (opcode == SETUP_FINALLY ||

1160+

opcode == SETUP_WITH ||

1161+

opcode == BEFORE_ASYNC_WITH ||

1162+

opcode == YIELD_FROM) {

1163+

/* Few cases where we skip running signal handlers and other

11611164

pending calls:

1162-

- If we're about to enter the try: of a try/finally (not

1165+

- If we're about to enter the 'with:'. It will prevent

1166+

emitting a resource warning in the common idiom

1167+

'with open(path) as file:'.

1168+

- If we're about to enter the 'async with:'.

1169+

- If we're about to enter the 'try:' of a try/finally (not

11631170

*very* useful, but might help in some cases and it's

11641171

traditional)

11651172

- If we're resuming a chain of nested 'yield from' or