STINNER Victor <vstin...@python.org> added the comment:
I can reproduce PyOS_InterruptOccurred() crash in Python 3.8 if I remove readline.cpython-38d-x86_64-linux-gnu.so and I disable EINTR error checking in my_fgets(): diff --git a/Parser/myreadline.c b/Parser/myreadline.c index 43e5583b8b..2712dedacd 100644 --- a/Parser/myreadline.c +++ b/Parser/myreadline.c @@ -73,7 +73,7 @@ my_fgets(char *buf, int len, FILE *fp) clearerr(fp); return -1; /* EOF */ } -#ifdef EINTR +#if 0 if (err == EINTR) { int s; PyEval_RestoreThread(_PyOS_ReadlineTState); vstinner@apu$ ./python Python 3.8.3+ (heads/3.8-dirty:00a240bf7f, Jun 1 2020, 17:00:22) [GCC 10.1.1 20200507 (Red Hat 10.1.1-1)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> ^C Erreur de segmentation (core dumped) I cannot reproduce the issue in Python 3.7. --- Python 3.7: --- int PyOS_InterruptOccurred(void) { if (_Py_atomic_load_relaxed(&Handlers[SIGINT].tripped)) { if (PyThread_get_thread_ident() != main_thread) return 0; _Py_atomic_store_relaxed(&Handlers[SIGINT].tripped, 0); return 1; } return 0; } --- Python 3.8: --- static int is_main(_PyRuntimeState *runtime) { unsigned long thread = PyThread_get_thread_ident(); PyInterpreterState *interp = _PyRuntimeState_GetThreadState(runtime)->interp; return (thread == runtime->main_thread && interp == runtime->interpreters.main); } int PyOS_InterruptOccurred(void) { if (_Py_atomic_load_relaxed(&Handlers[SIGINT].tripped)) { _PyRuntimeState *runtime = &_PyRuntime; if (!is_main(runtime)) { return 0; } _Py_atomic_store_relaxed(&Handlers[SIGINT].tripped, 0); return 1; } return 0; } --- is_main() function was added in Python 3.8 by: commit 64d6cc826dacebc2493b1bb5e8cb97828eb76f81 Author: Eric Snow <ericsnowcurren...@gmail.com> Date: Sat Feb 23 15:40:43 2019 -0700 bpo-35724: Explicitly require the main interpreter for signal-handling. (GH-11530) Ensure that the main interpreter is active (in the main thread) for signal-handling operations. This is increasingly relevant as people use subinterpreters more. https://bugs.python.org/issue35724 ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue40826> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com