You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.
I upgraded from Python 3.7.1 to 3.7.6 and began noticing a behavior that was breaking my code. My code detects if it's running in a virtualenv. This check worked in 3.7.1 but is broken in 3.7.6.
From the documentation, sys.prefix and sys.exec_prefix should point to the virtualenv when one is active. However, I'm seeing that both of these constants are pointing to the system installation directory and not my virtualenv when I am in a multiprocessing child. Here is an example output of a test application running in 3.7.6 (I've attached the test script to this ticket):
For 3.7, I can create a PR for that corrects the order of arguments passed into _winapi.CreateProcess
For 3.8 / master, the problem appears to be that the check in popen_spawn_win32.py to set the subprocess env is failing because sys.executable != spawn.get_executable() -- spawn.get_executable() is returning sys._base_executable. So, can you confirm that the fix is to just change spawn.get_executable() to return sys.executable, like it was prior to the PR mentioned in the other ticket?
can you confirm that the fix is to just change spawn.get_executable()
to return sys.executable, like it was prior to the PR mentioned in
the other ticket?
Yes, in spawn.py, change _python_exe = sys._base_executable to _python_exe = sys.executable. This is the value that gets returned by spawn.get_executable().
This will restore the operation of the following code in Popen.__init__ in popen_spawn_win32.py:
# bpo-35797: When running in a venv, we bypass the redirect# executor and launch our base Python.ifWINENVand_path_eq(python_exe, sys.executable):
This code switches to running the base executable in a virtual environment, which is required in order to support duplicating handles to the child or stealing handles from the parent. And the startup code in the child process is made aware of virtual environment via the "__PYVENV_LAUNCHER__" environment variable.