-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Several cmd.exe windows spawned when running virtualenv on Windows #1928
Comments
This is true, but I'm not sure what's your proposal as alternative. This works as designed. |
Can the windows be hidden? It's a background task, so should not pop up windows in the foreground. |
It should be possible to not show the windows. But the question is, why are there windows to show in the first place?note Normal subprocess calls use the CreateProcess API, and shouldn’t spawn a shell (which causes a window to show) at all. note I did not read the implementation in virtualenv. |
The implementation uses from subprocess import DETACHED_PROCESS, Popen
p = Popen(["py", "-c", "from time import sleep; sleep(5)"], creationflags=DETACHED_PROCESS) The relevant virtualenv code is here. |
I can’t say I understand the myriad of process and window flags in Win32 API, but if the process must be launched detached, I believe there are flags to hide/disable the window as well. |
Trying those, they don't seem to work 🙁 It seems to be somehow related to the chain of processes involved, as using |
@zooba do you happen to know the magic incantation to run a detached process without a new window showing up? It's crucial that this process runs detached because the upgrade can take a long time, a lot longer than the virtual environment creation. |
I call virtualenv.exe installed with pipx, so yeah, there are quite some indirections involved. virtualenv.exe is a wrapper that calls the venv python.exe, which is itself a wrapper (venvlauncher.exe) to the “real” python.exe.
Makes sense, thanks for the additional context. I’ll try some flag combinations myself as well and report back if I make any process. If all else fail, maybe it’d be doable to special-case Windows and launch |
I've raised https://bugs.python.org/issue41619 because I think the inconsistent behaviour at least needs better explanation. I suspect that the launcher is part of the issue here - the Python 3 virtual environment mechanism uses a modified version of the launcher (although I don't know if virtualenv uses that mechanism or has its own approach). Unfortunately, the details of that mechanism are undocumented, so it's hard to know what's intended and what's accidental... I think that even if there is a bug in Python here, virtualenv should work around it as the extra windows are not ideal. Hopefully the bug report will at least result in a more detailed explanation of what's going on here which will help us work out how to avoid them. |
At this point I'm not aware that's possible for virtualenv to work around it. I'm happy to workaround if somone provides a way to work around it in a reliable way. |
From the bpo issue, it looks like |
https://build.opensuse.org/request/show/840217 by user StevenK + dimstar_suse - Update to 20.0.33: * Fix ``None`` type error in cygwin if POSIX path in dest - by :user:`danyeaw`. (`#1962 <https://github.com/pypa/virtualenv/issues/1962>`_) * Fix Python 3.4 incompatibilities (added back to the CI) - by :user:`gaborbernat`. (`#1963 <https://github.com/pypa/virtualenv/issues/1963>`_) * For activation scripts always use UNIX line endings (unless it's BATCH shell related) - by :user:`saytosid`. (`#1818 <https://github.com/pypa/virtualenv/issues/1818>`_) * Avoid spawning new windows when doing seed package upgrades in the background on Windows - by :user:`gaborbernat`. (`#1928 <https://github.com/pypa/virtualenv/issues/1928>`_) * Fix a bug that reading and writing on the same file may cause race on multiple processes. (`#1938 <https://github.com/pypa/virtualenv/is
Issue
When virtualenv is run for the first time, multiple extra cmd.exe windows appear on the screen for a while.
This is probably easier to explain with a screencast: https://d.pr/v/yQMzXY
I assume those are used to check setuptools, pip, and wheel updates.
Environment
Provide at least:
OS: Windows
pip list
of the host python wherevirtualenv
is installed:Output of the virtual environment creation
Make sure to run the creation with
-vvv --with-traceback
:The text was updated successfully, but these errors were encountered: