pythonw should set `sys.stdout` and `sys.stdin` to valid objects.
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
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
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
首先在 Windows 上使用 pythonw 重現該行為,並查看 issue 中連結的討論以及 PyInstaller 關於缺少標準串流的文件。確定 pythonw 應如何提供有效的 sys.stdin 和 sys.stdout 物件,同時不破壞現有行為,然後驗證警告、logging 和與 print 相關的使用情境是否如預期運作。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- operating-systems
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100