summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-07-09 12:40:14 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2018-07-09 12:40:14 (GMT)
commit3f4d90d4d72921f16babd3f52d7df804916af224 (patch)
treec498d3f545a52424c129e7c6b0c0541df973755b /Python/ceval.c
parentcf7303ed2aa19fb48687d7140dbc86fc23c9fca4 (diff)
downloadcpython-3f4d90d4d72921f16babd3f52d7df804916af224.zip
cpython-3f4d90d4d72921f16babd3f52d7df804916af224.tar.gz
cpython-3f4d90d4d72921f16babd3f52d7df804916af224.tar.bz2
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()".
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 422a29e..90ad591 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