Skip to content

Commit 3f4d90d

Browse files
serhiy-storchakancoghlan
authored andcommitted
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()".
1 parent cf7303e commit 3f4d90d

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
@@ -928,11 +928,18 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
928928
Py_MakePendingCalls() above. */
929929

930930
if (_Py_atomic_load_relaxed(&_PyRuntime.ceval.eval_breaker)) {
931-
if (_Py_OPCODE(*next_instr) == SETUP_FINALLY ||
932-
_Py_OPCODE(*next_instr) == YIELD_FROM) {
933-
/* Two cases where we skip running signal handlers and other
931+
opcode = _Py_OPCODE(*next_instr);
932+
if (opcode == SETUP_FINALLY ||
933+
opcode == SETUP_WITH ||
934+
opcode == BEFORE_ASYNC_WITH ||
935+
opcode == YIELD_FROM) {
936+
/* Few cases where we skip running signal handlers and other
934937
pending calls:
935-
- If we're about to enter the try: of a try/finally (not
938+
- If we're about to enter the 'with:'. It will prevent
939+
emitting a resource warning in the common idiom
940+
'with open(path) as file:'.
941+
- If we're about to enter the 'async with:'.
942+
- If we're about to enter the 'try:' of a try/finally (not
936943
*very* useful, but might help in some cases and it's
937944
traditional)
938945
- If we're resuming a chain of nested 'yield from' or

0 commit comments

Comments
 (0)