@@ -19,6 +19,13 @@
|
19 | 19 | WINSERVICE = sys.executable.lower().endswith("pythonservice.exe") |
20 | 20 | |
21 | 21 | |
| 22 | +def _path_eq(p1, p2): |
| 23 | +return p1 == p2 or os.path.normcase(p1) == os.path.normcase(p2) |
| 24 | + |
| 25 | +WINENV = (hasattr(sys, '_base_executable') and |
| 26 | +not _path_eq(sys.executable, sys._base_executable)) |
| 27 | + |
| 28 | + |
22 | 29 | def _close_handles(*handles): |
23 | 30 | for handle in handles: |
24 | 31 | _winapi.CloseHandle(handle) |
@@ -50,12 +57,23 @@ def __init__(self, process_obj):
|
50 | 57 | pipe_handle=rhandle) |
51 | 58 | cmd = ' '.join('"%s"' % x for x in cmd) |
52 | 59 | |
| 60 | +python_exe = spawn.get_executable() |
| 61 | + |
| 62 | +# bpo-35797: When running in a venv, we bypass the redirect |
| 63 | +# executor and launch our base Python. |
| 64 | +if WINENV and _path_eq(python_exe, sys.executable): |
| 65 | +python_exe = sys._base_executable |
| 66 | +env = os.environ.copy() |
| 67 | +env["__PYVENV_LAUNCHER__"] = sys.executable |
| 68 | +else: |
| 69 | +env = None |
| 70 | + |
53 | 71 | with open(wfd, 'wb', closefd=True) as to_child: |
54 | 72 | # start process |
55 | 73 | try: |
56 | 74 | hp, ht, pid, tid = _winapi.CreateProcess( |
57 | | -spawn.get_executable(), cmd, |
58 | | -None, None, False, 0, None, None, None) |
| 75 | +python_exe, cmd, |
| 76 | +env, None, False, 0, None, None, None) |
59 | 77 | _winapi.CloseHandle(ht) |
60 | 78 | except: |
61 | 79 | _winapi.CloseHandle(rhandle) |
|