Reset PyInstaller environment on :restart

Starting with PyInstaller 6.10 (6.9?), we're supposed to tell PyInstaller when
we restart our application (and a subprocess should outlive this process).

In their words:

    The above requirement was introduced in PyInstaller 6.9, which changed the
    way the bootloader treats a process spawned via the same executable as its
    parent process. Whereas previously the default assumption was that it is
    running a new instance of (the same) program, the new assumption is that the
    spawned process is some sort of a worker subprocess that can reuse the
    already-unpacked resources. This change was done because the worker-process
    scenarios are more common, and more difficult to explicitly accommodate
    across various multiprocessing frameworks and other code that spawns worker
    processes via sys.executable.

https://pyinstaller.org/en/stable/common-issues-and-pitfalls.html#independent-subprocess
https://pyinstaller.org/en/stable/CHANGES.html (6.10)

While from a quick test on Windows, things still worked without setting the
variable (possibly because we don't use a onefile build), it still seems
reasonable to do what PyInstaller recommends doing.

Follow-up to #8269.
This commit is contained in:
Florian Bruhin 2024-08-13 16:03:54 +02:00
parent ba210f52f1
commit f3459a8f14
1 changed files with 8 additions and 1 deletions

View File

@ -177,10 +177,17 @@ class Quitter(QObject):
assert ipc.server is not None
ipc.server.shutdown()
if hasattr(sys, 'frozen'):
# https://pyinstaller.org/en/stable/common-issues-and-pitfalls.html#independent-subprocess
env = os.environ.copy()
env["PYINSTALLER_RESET_ENVIRONMENT"] = "1"
else:
env = None
# Open a new process and immediately shutdown the existing one
try:
args = self._get_restart_args(pages, session, override_args)
proc = subprocess.Popen(args) # pylint: disable=consider-using-with
proc = subprocess.Popen(args, env=env) # pylint: disable=consider-using-with
except OSError:
log.destroy.exception("Failed to restart")
return False