Give PyErr_CheckSignals guide-level documentation
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Documentation
Compiled extensions that "want to be interruptible by user requests" need to call PyErr_CheckSignals periodically; when it returns -1, they should stop work, clean up after themselves, and return to the interpreter.
This function is not mentioned at all in the extending and embedding guide, and its reference documentation makes it sound unimportant. As a result, many extension authors are (it seems to me) not aware that it exists or that they ought to be calling it, and so many extensions that should be interruptible by user requests aren't. For example, if you execute this code
>>> import numpy as np
>>> rng = np.random.default_rng()
>>> x = rng.random(1000000000)
and then immediately hit control-C, you'll be waiting at least a few seconds before you get the prompt back.
PyErr_CheckSignals also has the unusual property of potentially executing arbitrary Python code before returning to its caller, which makes it easy to use unsafely. Making an extension interruptible throughout may necessitate calling PyErr_CheckSignals from innermost loops where one would ideally release the GIL, which makes that worse (see #133465).
Thus, I suggest that a guide to correct use of PyErr_CheckSignals should be added to the extending and embedding guide.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia leggendo la guida all’estensione e all’incorporamento insieme alla documentazione di riferimento di PyErr_CheckSignals. Aggiungi una guida all’uso sicuro di PyErr_CheckSignals, inclusa la gestione di un valore restituito pari a -1, la pulizia e la sua potenziale capacità di eseguire codice Python arbitrario; la documentazione deve chiarire come le estensioni possano rimanere interrompibili.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- documentation
- Tipo di issue
- Documentazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 65/100