pythonw should set `sys.stdout` and `sys.stdin` to valid objects.
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず Windows で pythonw を使って動作を再現し、issue にリンクされている議論と、標準ストリームが存在しない場合についての PyInstaller ドキュメントを確認します。既存の動作を壊さずに pythonw が有効な sys.stdin オブジェクトと sys.stdout オブジェクトを提供する方法を判断し、そのうえで警告、ロギング、print に関連するユースケースが期待どおりに動作することを検証します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- operating-systems
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100