Skip to content

Windows: launch a Python outside WindowsApps before an alias (fixes #144) - #157

Closed
Vu Linh Truong (vulinh1704) wants to merge 1 commit into
microsoft:mainfrom
vulinh1704:fix/windows-hook-alias-144
Closed

Vu Linh Truong (vulinh1704) wants to merge 1 commit into
microsoft:mainfrom
vulinh1704:fix/windows-hook-alias-144

Conversation

@vulinh1704

Copy link
Copy Markdown
Contributor

Fixes #144.

On Windows the launchers took the first python3 on PATH. When that was an App Execution Alias under WindowsApps, they launched it once to probe it (-c "") and once more for the dispatcher. With the Python Install Manager, each alias launch starts an App Installer update check that AppXSvc never frees (python/pymanager#396), and the hook runs on every tool call.

te-hook and te now take python3, python and py from the first PATH directory outside WindowsApps that has them. The aliases are only tried, the same way as before, when there is no such Python. TE_PYTHON is still used as given. Linux and macOS go through the same TE_PYTHON, python3, python order as before.

This also fixes a related case: the Microsoft Store's stub aliases, which run nothing, used to hide a python.org Python later on PATH. The hook then fell back to py, or answered {} without it.

Python launches per hook event, counted with logging shims on PATH under Git Bash:

PATH before after
Install Manager alias, then %LOCALAPPDATA%\Python\bin (the setup in #144) 2 alias launches 1 launch, no alias
Store stubs, then a python.org Python 2 stub probes, then {} 1 launch
Install Manager alias only 2 2 (unchanged)

Tests: three new tests in tests/test_plugin_package.py set OS=Windows_NT and put logging stand-ins on PATH, so they also run on Linux and macOS. Two of them fail on the old launchers. The third pins that an alias is still the last resort. The full suite passes on Windows 11 (Git Bash, Python 3.12) and on Ubuntu 24.04 (dash as /bin/sh). I could not test with a real Install Manager install. The alias was a stand-in in a ...\Microsoft\WindowsApps directory, which is all the launcher looks at.

…ft#144)

The launchers took the first `python3` on PATH and, when it was an App Execution Alias under
WindowsApps, launched it once with `-c ""` to see that it runs and again for the dispatcher. With
the Python Install Manager, every alias launch starts an App Installer update check whose memory
AppXSvc never frees (python/pymanager#396), and the hook runs on every tool call.

Now python3, python and py come from the first PATH directory outside WindowsApps that has them,
and an alias is tried, as before, only when there is no such Python. With the Install Manager's
global shortcuts (%LOCALAPPDATA%\Python\bin) on PATH after WindowsApps, a hook event starts one
Python and no alias. A python.org Python after the Store's stub aliases is found as well; the
stub used to hide it, leaving only `py`, or `{}` without one. `TE_PYTHON` is used as it is, and
Linux and macOS are unchanged.
@SakshamUboweja

Copy link
Copy Markdown
Collaborator

Thanks for this! #153 fixes the same issue (#144) and is now merged. Your tests pass on main with it, so I’m closing this as a duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: te-hook launches the Python Install Manager alias twice per hook event; each launch leaks memory in AppXSvc (23.6 GB in 8 h)

2 participants