[utils] `Popen`: Reset PyInstaller environment (#11258)

- Forces spawning independent subprocesses for exes bundled with PyInstaller>=6.10
- Fixes regression introduced in fb8b7f226d
- Ref: https://pyinstaller.org/en/v6.10.0/CHANGES.html#incompatible-changes

Closes #11259
Authored by: bashonly, Grub4K

Co-authored-by: Simon Sawicki <contact@grub4k.xyz>
pull/11245/head^2
bashonly 2 months ago committed by GitHub
parent 64d84d75ca
commit fbc66e3ab3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -824,14 +824,18 @@ class Popen(subprocess.Popen):
_startupinfo = None _startupinfo = None
@staticmethod @staticmethod
def _fix_pyinstaller_ld_path(env): def _fix_pyinstaller_issues(env):
"""Restore LD_LIBRARY_PATH when using PyInstaller
Ref: https://github.com/pyinstaller/pyinstaller/blob/develop/doc/runtime-information.rst#ld_library_path--libpath-considerations
https://github.com/yt-dlp/yt-dlp/issues/4573
"""
if not hasattr(sys, '_MEIPASS'): if not hasattr(sys, '_MEIPASS'):
return return
# Force spawning independent subprocesses for exes bundled with PyInstaller>=6.10
# Ref: https://pyinstaller.org/en/v6.10.0/CHANGES.html#incompatible-changes
# https://github.com/yt-dlp/yt-dlp/issues/11259
env['PYINSTALLER_RESET_ENVIRONMENT'] = '1'
# Restore LD_LIBRARY_PATH when using PyInstaller
# Ref: https://pyinstaller.org/en/v6.10.0/runtime-information.html#ld-library-path-libpath-considerations
# https://github.com/yt-dlp/yt-dlp/issues/4573
def _fix(key): def _fix(key):
orig = env.get(f'{key}_ORIG') orig = env.get(f'{key}_ORIG')
if orig is None: if orig is None:
@ -845,7 +849,7 @@ class Popen(subprocess.Popen):
def __init__(self, args, *remaining, env=None, text=False, shell=False, **kwargs): def __init__(self, args, *remaining, env=None, text=False, shell=False, **kwargs):
if env is None: if env is None:
env = os.environ.copy() env = os.environ.copy()
self._fix_pyinstaller_ld_path(env) self._fix_pyinstaller_issues(env)
self.__text_mode = kwargs.get('encoding') or kwargs.get('errors') or text or kwargs.get('universal_newlines') self.__text_mode = kwargs.get('encoding') or kwargs.get('errors') or text or kwargs.get('universal_newlines')
if text is True: if text is True:

Loading…
Cancel
Save