question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

stderr duplication failed in console scripts

See original GitHub issue

Description

I use a console_scripts entry point with a test function. If I do pip install . or use setup.py to make a binary dist then install it, under some shell like Git Bash, running the created test-script.exe. stdin, stdout and stderr should all be set to a TextIOWrapper however, stderr is set to None.

The stderr handle is apparently not correctly set.

This is probably related to https://github.com/pypa/pip/issues/10444 and the fix introduced in Distlib 0.3.4 for a similar issue.

Expected behavior

$ test-script.exe
stdin=<_io.TextIOWrapper name='<stdin>' mode='r' encoding='cp1252'>
stdout=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='cp1252'>
stderr=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='cp1252'>

pip version

22.0

Python version

Python 3.7

OS

Windows

How to Reproduce

# setup.py
from setuptools import setup

setup(
    name="test",
    packages=["testing"],
    entry_points={
        "console_scripts": [
            "test-script=testing:main"
        ]
    }
)
# testing/__init__.py
import sys


def main():
    print(f"stdin={sys.stdin}")
    print(f"stdout={sys.stdout}")
    print(f"stderr={sys.stderr}")

Output

# With pip 21.*
$ test-script.exe
stdin=<_io.TextIOWrapper name='<stdin>' mode='r' encoding='cp1252'>
stdout=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='cp1252'>
stderr=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='cp1252'>

# With pip 22.0, 22.0.1 and 22.0.2 
$ test-script.exe
stdin=<_io.TextIOWrapper name='<stdin>' mode='r' encoding='cp1252'>
stdout=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='cp1252'>
stderr=None

Code of Conduct

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:55 (26 by maintainers)

github_iconTop GitHub Comments

8reactions
pradyunsgcommented, Feb 25, 2022

So the old version of distlib broke certain GUI use cases by making error dialog boxes pop up.

The new version of distlib broke other – CLI this time – use cases by making them error out silently.

This is good context, thanks for noting this here @eli-schwartz!

I think having a visible (albeit cryptic) error that users can discover is better than a silent error that they can’t. Further, CLI entry points are a lot more common than GUI entry points and I’m pretty sure the right thing to do here is to downgrade distlib to 0.3.3 until @vsajip is able able to fix this issue in distlib.

I’ll cut a bugfix for this.

3reactions
pierreluctgcommented, Feb 8, 2022

@carlkl I understand what the problem is, and I understand what we’d need to do to fix it (revert to an older distlib, or wait for a distlib fix). What I don’t know is how many people are affected, nor do I know whether this issue is more disruptive than the issue that the distlib upgrade fixed, or whether it will be more disruptive than the cost of making a bugfix release.

The comment you linked to says it is a “severe” bug. It’s not severe for me, I’ve never seen it happen. So if you can be more precise about what circumstances cause it to occur, that would make it easier to assess the severity in a way that doesn’t just boil down to “it doesn’t happen for me” vs “it happens for a program someone else uses a lot”. You also say “Now sys.stderr is None if you start launchers created by pip 22”. My reproducer above demonstrates that this isn’t always true. So the question is how often is that the case, and under what circumstances. I can’t tell, because as yet I haven’t ever had it happen for me.

🤷 I’m not really that bothered. Ultimately someone needs to make the case that this is important enough for us to produce a bugfix release with a reverted distlib. I’m only trying to help people make that case - if they don’t, then this will likely just wait for a fix in distlib, and the next pip release.

I have an example of a very common use case affected by this bug.

Imagine a python developer using Jenkins to run his unit tests, using pytest, on a Windows host.

Now because he start using pip 22.x (he updated because pip warned him that he was not using the latest version), running pytest will not produce any output on the console, tests will not run and there is no reporting.

Now how is this user supposed to root cause this issue? There is no output at all since stderr is None.

And this is not a intermittent issue, in the affected environment (like Jenkins on Windows in this example), stderr will always be None.

@pfmoore, I hope this helps you understand the importance of getting this bug fixed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

duplication of messages in stderr and stdout python logging
I'm using a small script and running it directly, and so the filter_maker will be in the __main__ module (as indicated in the...
Read more >
20.8. Error Reporting and Logging - PostgreSQL
The default is to log to stderr only. This parameter can only be set in the postgresql.conf file or on the server command...
Read more >
2 Server Error Message Reference - MySQL :: Developer Zone
Message: Can't write; duplicate key in table '%s'. Error number: 1024 ... Message: The used command is not allowed with this MySQL version....
Read more >
Node.js v19.3.0 Documentation
new Console(stdout[, stderr][, ignoreErrors]); new Console(options) ... Script cached data; DEP0111: process.binding(); DEP0112: dgram private APIs ...
Read more >
bash - Copy stdout and stderr to a log file and leave them on ...
Copy stdout and stderr to a log file and leave them on the console within the script itself [duplicate] · Ask Question. Asked...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found