Consider removing the thread and future handling in asyncio REPL
@ambv đang làm issue này rồi.
Từ ngày 21/10/2025.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
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.
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Đánh giá
Issue này chưa được đánh giá.