pythonw should set `sys.stdout` and `sys.stdin` to valid objects.
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ả
Bug report
Bug description:
So not exactly a bug -- but I wouldn't call it a feature request either, so I filed it as a bug.
The issue is that pythonw on Windows sets sys.stdout and sys.stdin to None.
This is problematic because while, e.g. print() will not fail, if not do anything useful, other things like warnings and logging, etc., may try to use stdout or stderr, and they will then fail.
See #107792 and #57791
So one might say: "don't do that" -- fair enough, except the user suffering from the problem may not be the one that wrote the code that's calling stderr -- it could be in a library, for instance. Library writers are often not thinking about windowed apps, and shouldn't have to do something special to accommodate them in any case.
See this note in the PyInstaller docs:
In which the solution is:
import sys
import os
if sys.stdout is None:
sys.stdout = open(os.devnull, "w")
if sys.stderr is None:
sys.stderr = open(os.devnull, "w")
It's not unreasonable for library authors to expect that stdout and stderr to be valid.
So couldn't pythonw add that code by default? users could override it themselves, of course.
NOTE: tested recently on py3.12 -- but this has been an issue for quite some time.
NOTE2: this isn't an issue on the Mac, because its pythonw redirects to the system off-screen console.
CPython versions tested on:
3.12
Operating systems tested on:
Windows
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 bằng cách tái hiện hành vi với pythonw trên Windows và xem lại các cuộc thảo luận được liên kết trong issue cùng tài liệu PyInstaller về các stream tiêu chuẩn bị thiếu. Xác định cách pythonw nên cung cấp các đối tượng sys.stdin và sys.stdout hợp lệ mà không làm ảnh hưởng đến hành vi hiện có, sau đó xác minh rằng các cảnh báo, logging và các trường hợp sử dụng liên quan đến print hoạt động như mong đợi.
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
- Lỗi
- Độ 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
- 35/100