Staging
v0.5.1
https://github.com/python/cpython
Revision e89f95bfd0881a9b80c3b1430d154a77bdf5a824 authored by Yury Selivanov on 09 June 2017, 21:06:39 UTC, committed by GitHub on 09 June 2017, 21:06:39 UTC
If we have a chain of generators/coroutines that are 'yield from'ing
each other, then resuming the stack works like:

- call send() on the outermost generator
- this enters _PyEval_EvalFrameDefault, which re-executes the
  YIELD_FROM opcode
- which calls send() on the next generator
- which enters _PyEval_EvalFrameDefault, which re-executes the
  YIELD_FROM opcode
- ...etc.

However, every time we enter _PyEval_EvalFrameDefault, the first thing
we do is to check for pending signals, and if there are any then we
run the signal handler. And if it raises an exception, then we
immediately propagate that exception *instead* of starting to execute
bytecode. This means that e.g. a SIGINT at the wrong moment can "break
the chain" – it can be raised in the middle of our yield from chain,
with the bottom part of the stack abandoned for the garbage collector.

The fix is pretty simple: there's already a special case in
_PyEval_EvalFrameEx where it skips running signal handlers if the next
opcode is SETUP_FINALLY. (I don't see how this accomplishes anything
useful, but that's another story.) If we extend this check to also
skip running signal handlers when the next opcode is YIELD_FROM, then
that closes the hole – now the exception can only be raised at the
innermost stack frame.

This shouldn't have any performance implications, because the opcode
check happens inside the "slow path" after we've already determined
that there's a pending signal or something similar for us to process;
the vast majority of the time this isn't true and the new check
doesn't run at all..
(cherry picked from commit ab4413a7e9bda95b6fcd517073e2a51dafaa1624)
1 parent b757745
History
Tip revision: e89f95bfd0881a9b80c3b1430d154a77bdf5a824 authored by Yury Selivanov on 09 June 2017, 21:06:39 UTC
[3.6] bpo-30039: Don't run signal handlers while resuming a yield from stack (GH-1081) (#1640)
Tip revision: e89f95b
File Mode Size
_asyncio.vcxproj -rw-r--r-- 3.0 KB
_asyncio.vcxproj.filters -rw-r--r-- 520 bytes
_bz2.vcxproj -rw-r--r-- 3.9 KB
_bz2.vcxproj.filters -rw-r--r-- 1.7 KB
_ctypes.vcxproj -rw-r--r-- 4.7 KB
_ctypes.vcxproj.filters -rw-r--r-- 2.3 KB
_ctypes_test.vcxproj -rw-r--r-- 3.1 KB
_ctypes_test.vcxproj.filters -rw-r--r-- 718 bytes
_decimal.vcxproj -rw-r--r-- 6.0 KB
_decimal.vcxproj.filters -rw-r--r-- 4.3 KB
_elementtree.vcxproj -rw-r--r-- 4.4 KB
_elementtree.vcxproj.filters -rw-r--r-- 2.5 KB
_freeze_importlib.vcxproj -rw-r--r-- 5.2 KB
_freeze_importlib.vcxproj.filters -rw-r--r-- 1.1 KB
_hashlib.vcxproj -rw-r--r-- 3.8 KB
_hashlib.vcxproj.filters -rw-r--r-- 436 bytes
_lzma.vcxproj -rw-r--r-- 3.7 KB
_lzma.vcxproj.filters -rw-r--r-- 435 bytes
_msi.vcxproj -rw-r--r-- 3.2 KB
_msi.vcxproj.filters -rw-r--r-- 423 bytes
_multiprocessing.vcxproj -rw-r--r-- 3.4 KB
_multiprocessing.vcxproj.filters -rw-r--r-- 861 bytes
_overlapped.vcxproj -rw-r--r-- 3.2 KB
_overlapped.vcxproj.filters -rw-r--r-- 434 bytes
_socket.vcxproj -rw-r--r-- 3.3 KB
_socket.vcxproj.filters -rw-r--r-- 702 bytes
_sqlite3.vcxproj -rw-r--r-- 4.5 KB
_sqlite3.vcxproj.filters -rw-r--r-- 2.4 KB
_ssl.vcxproj -rw-r--r-- 3.9 KB
_ssl.vcxproj.filters -rw-r--r-- 428 bytes
_testbuffer.vcxproj -rw-r--r-- 3.1 KB
_testbuffer.vcxproj.filters -rw-r--r-- 435 bytes
_testcapi.vcxproj -rw-r--r-- 3.1 KB
_testcapi.vcxproj.filters -rw-r--r-- 439 bytes
_testconsole.vcxproj -rw-r--r-- 3.2 KB
_testconsole.vcxproj.filters -rw-r--r-- 952 bytes
_testembed.vcxproj -rw-r--r-- 3.1 KB
_testembed.vcxproj.filters -rw-r--r-- 948 bytes
_testimportmultiple.vcxproj -rw-r--r-- 3.2 KB
_testimportmultiple.vcxproj.filters -rw-r--r-- 444 bytes
_testmultiphase.vcxproj -rw-r--r-- 3.2 KB
_testmultiphase.vcxproj.filters -rw-r--r-- 952 bytes
_tkinter.vcxproj -rw-r--r-- 3.9 KB
_tkinter.vcxproj.filters -rw-r--r-- 534 bytes
build.bat -rw-r--r-- 5.7 KB
build_env.bat -rw-r--r-- 26 bytes
clean.bat -rw-r--r-- 131 bytes
env.bat -rw-r--r-- 728 bytes
field3.py -rw-r--r-- 974 bytes
get_externals.bat -rw-r--r-- 2.9 KB
idle.bat -rw-r--r-- 311 bytes
libeay.vcxproj -rw-r--r-- 45.3 KB
liblzma.vcxproj -rw-r--r-- 13.0 KB
openssl.props -rw-r--r-- 3.5 KB
pcbuild.proj -rw-r--r-- 5.5 KB
pcbuild.sln -rw-r--r-- 58.2 KB
prepare_ssl.bat -rw-r--r-- 281 bytes
prepare_ssl.py -rw-r--r-- 6.3 KB
pyexpat.vcxproj -rw-r--r-- 3.6 KB
pyexpat.vcxproj.filters -rw-r--r-- 1.1 KB
pylauncher.vcxproj -rw-r--r-- 3.2 KB
pylauncher.vcxproj.filters -rw-r--r-- 1.2 KB
pyproject.props -rw-r--r-- 9.4 KB
pyshellext.vcxproj -rw-r--r-- 3.4 KB
pyshellext.vcxproj.filters -rw-r--r-- 1.4 KB
python.props -rw-r--r-- 10.4 KB
python.vcxproj -rw-r--r-- 4.6 KB
python.vcxproj.filters -rw-r--r-- 824 bytes
python3dll.vcxproj -rw-r--r-- 5.8 KB
python3dll.vcxproj.filters -rw-r--r-- 1.2 KB
pythoncore.vcxproj -rw-r--r-- 21.5 KB
pythoncore.vcxproj.filters -rw-r--r-- 32.5 KB
pythonw.vcxproj -rw-r--r-- 3.0 KB
pythonw.vcxproj.filters -rw-r--r-- 702 bytes
pywlauncher.vcxproj -rw-r--r-- 3.2 KB
pywlauncher.vcxproj.filters -rw-r--r-- 1.2 KB
readme.txt -rw-r--r-- 12.2 KB
rmpyc.py -rw-r--r-- 409 bytes
rt.bat -rw-r--r-- 2.0 KB
select.vcxproj -rw-r--r-- 3.2 KB
select.vcxproj.filters -rw-r--r-- 436 bytes
sqlite3.vcxproj -rw-r--r-- 4.1 KB
sqlite3.vcxproj.filters -rw-r--r-- 804 bytes
ssleay.vcxproj -rw-r--r-- 4.8 KB
tcl.vcxproj -rw-r--r-- 3.5 KB
tcltk.props -rw-r--r-- 3.1 KB
tix.vcxproj -rw-r--r-- 3.5 KB
tk.vcxproj -rw-r--r-- 3.7 KB
unicodedata.vcxproj -rw-r--r-- 3.2 KB
unicodedata.vcxproj.filters -rw-r--r-- 810 bytes
winsound.vcxproj -rw-r--r-- 3.1 KB
winsound.vcxproj.filters -rw-r--r-- 500 bytes
xxlimited.vcxproj -rw-r--r-- 3.2 KB
xxlimited.vcxproj.filters -rw-r--r-- 433 bytes

readme.txt

back to top