python / python/cpython

IDLE - there is no known way to trigger atexit functions

Aperta
#98,318 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

topic-IDLE type-bug
Lingua principale
Python
Stelle
77.2k
Fork
36k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Bug report

Hello!

So this has been an issue that has probably been bugging many people for a while now. This has bitten me back when I was a newbie as well, learning python using IDLE. This issue does not personally affect me anymore since I've mostly moved on from IDLE, but for the sake of others new to the language, I would like to formalise this issue on the tracker.

Here is a pure python MRE that demonstrates what I'm saying

import atexit
import time

@atexit.register
def done():
    print("Exiting application!")

time.sleep(1)

When I run this on the command-line with no flags, I see the text printed after the program runs for a second and exits. On IDLE, this just runs for a second and exits without printing anything.

So I later realised that IDLE runs programs with the -i flag. But on the commandline I can do a ctrl+z and get the interpreter to actually stop and handle atexit. This is not apparent in IDLE shell, where there does not seem to be any distinction between the "regular interactive state", and the "previous module run interactive state". And neither does ctrl+c/z/d work. A hard shell restart also does not lead to anything being printed.

I've glanced through the issue tracker with a quick search and I didn't find a duplicate of this issue, but incase I'm mistaken, my apologies; this issue can be closed.

Your environment

  • CPython versions tested on: 3.10 (but from my memory, it happened on all previous versions too)
  • Operating system and architecture: Windows 11 64-bit (In my understanding it also happens on other architectures and OSes)

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia eseguendo in IDLE e dalla riga di comando il riproduttore di atexit fornito, scritto esclusivamente in Python, quindi confronta gli stati normale e successivo all'esecuzione del modulo della shell di IDLE. Il lavoro è completato quando IDLE offre un modo chiaro per raggiungere lo stato dell'interprete che esegue le funzioni atexit registrate, con l'output segnalato che appare dopo l'uscita dal modulo.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
desktop, tooling
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.