Treat `KeyboardInterrupt` or `SystemExit` the same on program exit even if they are inside exception groups
Chưa có ai nhận issue này.
- 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ả
Feature or enhancement
Proposal:
A KeyboardInterrupt or SystemExit inside a BaseExceptionGroup should be treated like a bare KeyboardInterrupt or SystemExit.
PS C:\...> python x.py
+ Exception Group Traceback (most recent call last):
| File "C:\...\x.py", line 1, in <module>
| raise BaseExceptionGroup("ki in an exception group", [KeyboardInterrupt()])
| BaseExceptionGroup: ki in an exception group (1 sub-exception)
+-+---------------- 1 ----------------
| KeyboardInterrupt
+------------------------------------
PS C:\...> $LastExitCode
1
PS C:\...> python x.py
Traceback (most recent call last):
File "C:\...\x.py", line 1, in <module>
raise KeyboardInterrupt()
KeyboardInterrupt
PS C:\...> $LastExitCode
-1073741510
Looking at the CPython source code, I believe _Py_HandleSystemExitAndKeyboardInterrupt is the relevant function.
Points for it:
- less pitfalls for a 3rd party using exception groups
- see any other failures (as exceptions) upon shutdown (ATM the workaround requires discarding the other exceptions)
Points against:
SystemExitin an exception group prints out the stack trace, unlike when it's not in an exception group- we could make them consistent (filter out
SystemExitand print the exception group then)
- we could make them consistent (filter out
I volunteer to implement this if this is fine.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
EDIT: I have now made a post. See https://discuss.python.org/t/keyboardinterrupt-and-systemexit-in-exception-groups-should-be-considered-for-pythons-exit-code/82816
Links to previous discussion of this feature:
I have tried some basic keyword searches as well as some digging in blame, but I can't find any previous discussion.
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.
Hướng nghiên cứu
Bắt đầu với _Py_HandleSystemExitAndKeyboardInterrupt của CPython, được issue xác định là entry point liên quan, và tái hiện hai ví dụ về mã thoát bằng một script phát sinh một exception đơn lẻ và một script bên trong một BaseExceptionGroup. Đọc thảo luận được liên kết trước khi quyết định nên xử lý đầu ra của SystemExit như thế nào; hoàn tất khi KeyboardInterrupt và SystemExit được nhóm tuân theo hành vi thoát độc lập dự kiến.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- operating-systems
- Loại issue
- Tính năng
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 45/100