Skip to content

Commit eeaae26

Browse files
[3.6] bpo-34066: Disabled interruption before SETUP_WITH and BEFORE_ASYNC_WITH. (GH-8159) (GH-8198)
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()". (cherry picked from commit 3f4d90d) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 13d1025 commit eeaae26

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed
Lines changed: 2 additions & 0 deletions
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()``.

Python/ceval.c

Lines changed: 11 additions & 4 deletions
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

0 commit comments

Comments
 (0)