pythonw should set `sys.stdout` and `sys.stdin` to valid objects.
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the behavior with pythonw on Windows and review the issue's linked discussions and PyInstaller documentation about missing standard streams. Determine how pythonw should provide valid sys.stdin and sys.stdout objects without breaking existing behavior, then verify that warnings, logging, and print-related use cases work as expected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100