Skip to content

Commit

Permalink
[utils] Popen: Reset PyInstaller environment (yt-dlp#11258)
Browse files Browse the repository at this point in the history
- Forces spawning independent subprocesses for exes bundled with PyInstaller>=6.10
- Fixes regression introduced in fb8b7f2
- Ref: https://pyinstaller.org/en/v6.10.0/CHANGES.html#incompatible-changes

Closes yt-dlp#11259
Authored by: bashonly, Grub4K

Co-authored-by: Simon Sawicki <contact@grub4k.xyz>
  • Loading branch information
bashonly and Grub4K authored Oct 16, 2024
1 parent 64d84d7 commit fbc66e3
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions yt_dlp/utils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,14 +824,18 @@ class Popen(subprocess.Popen):
_startupinfo = None

@staticmethod
def _fix_pyinstaller_ld_path(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
"""
def _fix_pyinstaller_issues(env):
if not hasattr(sys, '_MEIPASS'):
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):
orig = env.get(f'{key}_ORIG')
if orig is None:
Expand All @@ -845,7 +849,7 @@ def _fix(key):
def __init__(self, args, *remaining, env=None, text=False, shell=False, **kwargs):
if env is None:
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')
if text is True:
Expand Down

0 comments on commit fbc66e3

Please sign in to comment.