Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] stderr duplication failed #10444

Closed
1 task done
rayzchen opened this issue Aug 16, 2021 · 133 comments · Fixed by #11267
Closed
1 task done

[BUG] stderr duplication failed #10444

rayzchen opened this issue Aug 16, 2021 · 133 comments · Fixed by #11267
Labels
OS: windows Windows specific project: vendored dependency Related to a vendored dependency type: bug A confirmed bug or unintended behavior
Milestone

Comments

@rayzchen
Copy link

setuptools version

setuptools==56.0.0

Python version

Python 3.9

OS

Windows

Additional environment information

No response

Description

I use gui_scripts with a blank function. If i use pip install -e . or py setup.py install nothing happens, as expected. If i do pip install . or use setup.py to make a binary dist then install it, i get stderr duplication failed in a prompt. This happens before any code gets run.

Expected behavior

Nothing

How to Reproduce

# setup.py
from setuptools import setup

setup(
    name="test",
    packages=["test"],
    entry_points={
        "gui_scripts": [
            "test-script=test:main"
        ]
    }
)
# test/__init__.py
def main():
    pass

Run above commands

Output

image

Code of Conduct

  • I agree to follow the PSF Code of Conduct
@jaraco
Copy link
Member

jaraco commented Sep 6, 2021

The reason you're seeing this error only in the selected environments (non-editable install) is because only editable installs use Setuptools' launcher scripts. The error you're getting is from the launcher scripts installed by pip and distlib. You'll want to report the issue to the distlib project and see that pip inherits the fix. For that reason, I'll move this issue to pip and I recommend you to file an issue with distlib.

@jaraco jaraco transferred this issue from pypa/setuptools Sep 6, 2021
@DiddiLeija
Copy link
Member

@rayzchen Is this still happening? Could you provide some information of the pip version you are using?

@DiddiLeija DiddiLeija added S: needs triage Issues/PRs that need to be triaged type: bug A confirmed bug or unintended behavior S: awaiting response Waiting for a response/more information labels Sep 23, 2021
@rayzchen
Copy link
Author

It still happens with pip version 21.2.4

@no-response no-response bot removed the S: awaiting response Waiting for a response/more information label Sep 24, 2021
@uranusjr
Copy link
Member

cc @vsajip since the launchers are from distlib.

@vsajip
Copy link
Contributor

vsajip commented Sep 25, 2021

I can't reproduce this - it might be something specific in @rayzchen 's environment. I'm using Python 3.9.7 on Windows 10.

C:\Users\Vinay\Projects\scratch\distlib\pip_10444> type setup.py                                                                   
from setuptools import setup                                                                                                       
                                                                                                                                   
setup(                                                                                                                             
    name="test",                                                                                                                   
    packages=["test"],                                                                                                             
    entry_points={                                                                                                                 
        "gui_scripts": [                                                                                                           
            "test-script=test:main"                                                                                                
        ]                                                                                                                          
    }                                                                                                                              
)                                                                                                                                  
C:\Users\Vinay\Projects\scratch\distlib\pip_10444> type test\__init__.py                                                           
def main():                                                                                                                        
    pass                                                                                                                           
C:\Users\Vinay\Projects\scratch\distlib\pip_10444> python3 -m venv env                                                             
                                                                                                                                   
C:\Users\Vinay\Projects\scratch\distlib\pip_10444> env\Scripts\python -m pip install -U pip wheel                                  
Requirement already satisfied: pip in c:\users\vinay\projects\scratch\distlib\pip_10444\env\lib\site-packages (21.2.3)             
Collecting pip                                                                                                                     
  Using cached pip-21.2.4-py3-none-any.whl (1.6 MB)                                                                                
Collecting wheel                                                                                                                   
  Using cached wheel-0.37.0-py2.py3-none-any.whl (35 kB)                                                                           
Installing collected packages: wheel, pip                                                                                          
  Attempting uninstall: pip                                                                                                        
    Found existing installation: pip 21.2.3                                                                                        
    Uninstalling pip-21.2.3:                                                                                                       
      Successfully uninstalled pip-21.2.3                                                                                          
Successfully installed pip-21.2.4 wheel-0.37.0                                                                                     
                                                                                                                                   
C:\Users\Vinay\Projects\scratch\distlib\pip_10444> env\Scripts\pip install .                                                       
Processing c:\users\vinay\projects\scratch\distlib\pip_10444                                                                       
  DEPRECATION: A future pip version will change local packages to be built in-place without first copying to a temporary directory.
 We recommend you use --use-feature=in-tree-build to test your packages with this new behavior before it becomes the default.      
   pip 21.3 will remove support for this functionality. You can find discussion regarding this at https://github.com/pypa/pip/issue
s/7555.                                                                                                                            
Building wheels for collected packages: test                                                                                       
  Building wheel for test (setup.py) ... done                                                                                      
  Created wheel for test: filename=test-0.0.0-py3-none-any.whl size=1357 sha256=59ca865995d18af94cae5d4bf40bc7643ffa08ff8fdcd29e10b
9a8c940967239                                                                                                                      
  Stored in directory: C:\Users\Vinay\AppData\Local\Temp\pip-ephem-wheel-cache-fir7qy3v\wheels\6f\a7\45\f9fb5d415c64f56b92837eabf4b
edd182318b9abca73407cd5                                                                                                            
Successfully built test                                                                                                            
Installing collected packages: test                                                                                                
Successfully installed test-0.0.0                                                                                                  
                                                                                                                                   
C:\Users\Vinay\Projects\scratch\distlib\pip_10444> dir env\Scripts\                                                                
 Volume in drive C has no label.                                                                                                   
 Volume Serial Number is 26B4-06F0                                                                                                 
                                                                                                                                   
 Directory of C:\Users\Vinay\Projects\scratch\distlib\pip_10444\env\Scripts                                                        
                                                                                                                                   
25/09/2021  06:49    <DIR>          .                                                                                              
25/09/2021  06:49    <DIR>          ..                                                                                             
25/09/2021  06:48             1,997 activate                                                                                       
25/09/2021  06:48               989 activate.bat                                                                                   
25/09/2021  06:48            19,408 Activate.ps1                                                                                   
25/09/2021  06:48               368 deactivate.bat                                                                                 
25/09/2021  06:49           106,383 pip.exe                                                                                        
25/09/2021  06:49           106,383 pip3.9.exe                                                                                     
25/09/2021  06:49           106,383 pip3.exe                                                                                       
25/09/2021  06:48           543,464 python.exe                                                                                     
25/09/2021  06:48           542,440 pythonw.exe                                                                                    
25/09/2021  06:49           100,222 test-script.exe                                                                                
25/09/2021  06:48           106,370 wheel.exe                                                                                      
              11 File(s)      1,634,407 bytes                                                                                      
               2 Dir(s)  11,182,489,600 bytes free                                                                                 
                                                                                                                                   
C:\Users\Vinay\Projects\scratch\distlib\pip_10444> env\Scripts\test-script.exe                                                     
                                                                                                                                   
C:\Users\Vinay\Projects\scratch\distlib\pip_10444>                                                                                 

And no error dialog box comes up. If I additionally install pywin32, change the test application to the following:

# setup.py
from setuptools import setup

setup(
    name="test",
    packages=["test"],
    entry_points={
        "gui_scripts": [
            "test-script=test:main",
            "hello=test:hello"
        ]
    }
)

# test\__init__.py
def main():
    pass
    
def hello():
    import win32api, win32con
    win32api.MessageBox (0, "Test application says 'Hello, world!'", 'Hello, world!', win32con.MB_OK)
    pass

and reinstall using env\Scripts\pip install . followed by running env\Scripts\hello, I get the expected message box:
ss02

@pradyunsg pradyunsg added OS: windows Windows specific S: awaiting response Waiting for a response/more information and removed S: needs triage Issues/PRs that need to be triaged labels Sep 25, 2021
@rayzchen
Copy link
Author

I tried the exact same thing that you did and I still got the error. What does the error actually mean? I'm using python 3.9.4, and I upgraded setuptools to 57.0.0.

@no-response no-response bot removed the S: awaiting response Waiting for a response/more information label Sep 25, 2021
@rayzchen
Copy link
Author

sys.version is 3.9.4 (tags/v3.9.4:1f2e308, Apr 6 2021, 13:22:44) [MSC v.1928 32 bit (Intel)]

@vsajip
Copy link
Contributor

vsajip commented Sep 25, 2021

What does the error actually mean?

It means that the Windows DuplicateHandle API failed (returned an error) for the stderr process stream, and the launcher bails out because that happened. The launcher calls code to duplicate handles for stdin, stdout and stderr in that order; I don't know why the duplication of stderr is failing for you where stdin and stdout apparently succeed just before that. According to the linked Windows documentation,

The handle must have the PROCESS_DUP_HANDLE access right.

I have no way of telling if that's the case in your environment, of course. What Windows version is it where the failure occurs? That might be relevant.

@rayzchen
Copy link
Author

image
if this helps

@vsajip
Copy link
Contributor

vsajip commented Sep 25, 2021

Can you please confirm that it's running on a 64-bit processor? Can you please try with a 64-bit Python? Your version string seems to indicate a 32-bit Python.

@vsajip
Copy link
Contributor

vsajip commented Sep 25, 2021

@rayzchen I used the script in this Gist to see if I could duplicate handles on my system using ctypes. When I ran it, I got

1
1
1

Indicating that stdin, stdout and stderr were successfully duplicated. You might want to try it, but make sure you're OK with what it does first.

@DiddiLeija DiddiLeija added the S: awaiting response Waiting for a response/more information label Oct 19, 2021
@no-response
Copy link

no-response bot commented Nov 3, 2021

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

@jeremyd2019
Copy link

This was reported at msys2/MSYS2-packages#2694. Your handles.py script returns 1 1 1 when run via python, but if I modify the script to use MessageBoxW instead of print, and run via pythonw instead, I got 0 0 0.

Outputting the handle values, input and output are 0, and only error is an actual handle.

def MessageBox(message):
    return windll.user32.MessageBoxW(0, str(message), "Your title", 1)

The last error from DuplicateHandle is 6 (ERROR_INVALID_HANDLE) for in and out, and 50 (ERROR_NOT_SUPPORTED) for error.

@jeremyd2019
Copy link

When run from cmd.exe, all 3 handles are 0, and all 3 DuplicateHandle calls error with ERROR_INVALID_HANDLE)

@vsajip
Copy link
Contributor

vsajip commented Nov 13, 2021

Not sure exactly what you mean by "run from cmd.exe" - I originally ran the handles.py from a cmd.exe window to get the 1 1 1 result. It's possible that a windowed application like pythonw doesn't have these handles because it doesn't do terminal I/O. It's not clear why only stderr would be affected.

@jeremyd2019
Copy link

jeremyd2019 commented Nov 13, 2021

Sorry. The report to MSYS2 was that they got this error from a GUI launcher when launched from Git for Windows Bash but not when launched from cmd or powershell. I was testing using MSYS2 (Git for Windows uses a fork of MSYS2, and in turn MSYS2 is a fork of Cygwin).

@rayzchen
Copy link
Author

rayzchen commented Nov 14, 2021 via email

@no-response no-response bot removed the S: awaiting response Waiting for a response/more information label Nov 14, 2021
@vsajip
Copy link
Contributor

vsajip commented May 9, 2022

Any reason you can't download the built launchers in the distlib repo

https://github.com/pypa/distlib/raw/master/distlib/{t32,t64,w32,w64}.exe

and test with those? Just to ensure that what gets into the next distlib release is fit for purpose.

@carlkl
Copy link

carlkl commented May 9, 2022

I forgot that the binaries are contained in the repo - thanks.

@cbrnr
Copy link

cbrnr commented May 9, 2022

I confirm that the mnelab launcher (a GUI app) works with the latest launchers.

@rayzchen
Copy link
Author

rayzchen commented May 9, 2022

If this helps, the error happens with pythonw when running any script. However a fresh install of Python 3.10.4 x64 seems to work fine. Is it because I'm using 32-bit 3.9? I'm not too keen on migrating everything from 3.9 to 3.10.

@vsajip
Copy link
Contributor

vsajip commented May 9, 2022

@rayzchen Just to be clear - are you saying this error still occurs with the latest launchers patched into pip? Please list the exact steps you took to run the tests in the failure case, starting from the launchers in the latest distlib repo.

@rayzchen
Copy link
Author

rayzchen commented May 9, 2022

It's my current setup which shouldn't have been modified since I opened this issue, which I guess isn't much help anymore. How do I get the new launcher?

@vsajip
Copy link
Contributor

vsajip commented May 9, 2022

You clone the distlib repository and look for the .exe files in the distlib directory under the project root.

@carlkl
Copy link

carlkl commented May 10, 2022

I tested the latest pip together with the updated binaries from the latest distlib. I can confirm this works with cli with both; msys2 as well as with the Windows cmd prompt.

@vsajip
Copy link
Contributor

vsajip commented May 10, 2022

Thanks @cbrnr and @carlkl for redoing the tests. Looking promising 🤞

@uranusjr uranusjr added this to the 22.1 milestone May 10, 2022
@uranusjr
Copy link
Member

Not sure if we already upgraded distlib in 22.1, adding this to the milestone just to be sure.

@pradyunsg pradyunsg removed this from the 22.1 milestone May 11, 2022
@pradyunsg
Copy link
Member

The distlib changes haven't been released. #11063 did not update to distlib 0.3.4 since that was the problematic version. Once there's a new distlib release containing the fixed launchers, we can update the vendored distlib. :)

@vsajip
Copy link
Contributor

vsajip commented May 11, 2022

Just waiting for a response from @rayzchen (and anyone else) and then I should be able to cut a release soon after that.

@vsajip
Copy link
Contributor

vsajip commented Jul 14, 2022

Didn't hear from @rayzchen, but distlib 0.3.5 has just been released on PyPI.

@pradyunsg
Copy link
Member

@sbidoul FYI: when you do the vendoring update, this issue should be closed.

@rayzchen
Copy link
Author

Sorry for the late reply, but which one do I download, w64.exe or t64.exe?

@rayzchen
Copy link
Author

I tried both but I get Fatal error in launcher: Unable to find an appended archive. with both

@sbidoul sbidoul added this to the 22.2 milestone Jul 14, 2022
@vsajip
Copy link
Contributor

vsajip commented Jul 14, 2022

I tried both but I get Fatal error in launcher: Unable to find an appended archive. with both

You can't just run the launchers, if that's what you tried. What did you actually do with the launchers?

@rayzchen
Copy link
Author

Double click it, I guess?

@sbidoul
Copy link
Member

sbidoul commented Jul 14, 2022

@sbidoul FYI: when you do the vendoring update, this issue should be closed.

Ok. I'll be glad if anyone is able to provide a changelog entry for this issue, though.

@vsajip
Copy link
Contributor

vsajip commented Jul 14, 2022

Double click it, I guess?

No, that just runs the launcher by itself, which would fail in the way you saw. What needs to be done is for the executables from the latest distlib version to be copied over the vendored ones in pip, and then use that pip to install a package with scripts, and then run one of those scripts from wherever they were installed to ...

@rayzchen
Copy link
Author

Ah, got it. The new executables work now, I don't get the error.

Just out of curiosity, how do I use the executables to create scripts? Is it something like running

copy w32.exe + some_file.pyz out.exe

like using 7z.sfx?

@vsajip
Copy link
Contributor

vsajip commented Jul 14, 2022

Well, the easiest way is to use ScriptMaker from distlib. What you've said is more or less right, but you have to factor in the shebang, too. Otherwise the launcher can't tell which interpreter is to run the archive.

@sbidoul sbidoul added the project: vendored dependency Related to a vendored dependency label Jul 15, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
OS: windows Windows specific project: vendored dependency Related to a vendored dependency type: bug A confirmed bug or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.