python / python/cpython

Consider removing the thread and future handling in asyncio REPL

Aperta
#140,355 5 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@ambv ci sta già lavorando.

Dal 21/10/2025.

stdlib topic-asyncio type-feature
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Bug report

Bug description:

In the current asyncio REPL, the event loop runs in the main thread, while the interactive console operates in a separate thread as both are running blocking loops. This leads to issues with console input handling, as noted in issue gh-140163 and gh-138827.

https://github.com/python/cpython/blob/d86ad870cc112d4bd36165398368826746555730/Lib/asyncio/__main__.py#L226-L240

While this is a MacOS-specific issue, it reveals a defect of the existing implementation. Specifically, the REPL can never receives Ctrl-C event and set the readline status properly, as it does normally. As the above code shows, the outer-most loop catches the KeyboardInterrupt and sets a flag, then tells the REPL to respond. However, the console loop never stops when this happens, because you can't actually interrupt input() from outside the thread, making it unable to respond to outer events.

So I rethink of the necessity of separate threads and also refer to the implementation of IPython. In a REPL, each cell is executed, and the result is awaited. There doesn't seem to be a need for a concurrent setup. A simple loop.run_until_complete() will do, as IPython does. At the same time, this can also greatly simplify the existing code.

However, I know I could be very wrong. So please correct me.

DPO link: https://discuss.python.org/t/consider-removing-the-thread-and-future-handling-in-asyncio-repl/104457

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs
  • gh-140356

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.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.