Builtin input does not always correctly handle errors from `PyOS_Readline`
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 35.9k
- Métriques de merge des PR
- Métriques de PR en attente
Description
Assertion failure sending SIGINT while calling input
import os, signal, threading
send = threading.Event()
def interrupter():
while True:
send.wait()
os.kill(os.getpid(), signal.SIGINT)
threading.Thread(target=interrupter).start()
send.set()
while True:
try:
input(">")
except KeyboardInterrupt:
pass
Note, this is a modified version of the example code in #112585.
Python (tested v3.12.10, v3.13.3, v3.14.0b1, and current HEAD), built with assertions enabled:
~/src/cpython/ $ ./python crash.py
>>>>>>>>>>>python: Objects/call.c:342: _PyObject_Call: Assertion `!_PyErr_Occurred(tstate)' failed.
Aborted (core dumped)
IIUC the issue is builtin_input_impl in Python/bltinmodule.c calls PyOS_Readline but assumes it cannot set an exception:
s = PyOS_Readline(stdin, stdout, promptstr);
if (s == NULL) {
PyErr_CheckSignals();
if (!PyErr_Occurred())
PyErr_SetNone(PyExc_KeyboardInterrupt);
If PyOS_Readline sets an exception (e.g. as in this case by running an interrupt signal handler itself), as opposed to being interrupted by a signal and returning NULL without setting the exception, and another signal with a handler is pending when PyErr_CheckSignals() is called, the handler will be called with the prior exception already set, and hence the assertion fails.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
No response
Linked PRs
- gh-134645
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez dans Python/bltinmodule.c, au niveau de builtin_input_impl, et reproduisez l’assertion avec l’exemple de signal et d’entrée fourni. Suivez la manière dont PyOS_Readline et PyErr_CheckSignals gèrent une exception existante ; le travail est terminé lorsque la reproduction n’interrompt plus son exécution avec l’assertion _PyObject_Call et préserve le comportement d’interruption attendu.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- operating-systems
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 35/100