File: pyi_splash_in_subprocess.py

package info (click to toggle)
pyinstaller 6.18.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,820 kB
  • sloc: python: 41,828; ansic: 12,123; makefile: 171; sh: 131; xml: 19
file content (52 lines) | stat: -rw-r--r-- 1,862 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import sys
import subprocess
import time

in_child = False
if len(sys.argv) == 2:
    assert sys.argv[1] == 'child', f"Unexpected argument: {sys.argv[1]}"
    in_child = True

# pyi_splash must be should be always importable
import pyi_splash  # noqa: E402

# Check module's guts to validate its state. Not for public use...

# Module must be marked as initialized, regardless of whether splash screen is active or suppressed.
assert pyi_splash._initialized, "Module is not marked as initialized!"

if in_child:
    # IPC port must be zero
    assert pyi_splash._ipc_port == 0, f"Unexpected IPC port value: {pyi_splash._ipc_port}"

    # Connection must be left closed
    assert pyi_splash._ipc_socket_closed, \
        "Unexpected splash screen socket state - expected it to be closed, but it is open!"
else:
    # IPC port must be valid
    assert pyi_splash._ipc_port > 0, f"Unexpected IPC port value: {pyi_splash._ipc_port}"

    # Connection must have been established
    assert not pyi_splash._ipc_socket_closed, \
        "Unexpected splash screen socket state - expected it to be open, but it is closed!"

# Test of public API

# is_alive() should reflect the actual status (True in parent, False in child process).
assert pyi_splash.is_alive() != in_child, "Unexpected splash screen status!"

# update_text() should either succeed or be a no-op. Most importantly, it should not raise an error when splash
# screen is suppressed.
pyi_splash.update_text("Updated text")
time.sleep(1)

# Same goes for close().
pyi_splash.close()

# After close, splash screen should be inactive (if it ever was active)
assert not pyi_splash.is_alive(), "Splash screen is not inactive!"

# If we are the parent process, spawn the child
if not in_child:
    print("Spawning the child process...", file=sys.stderr)
    subprocess.run([sys.executable, "child"], check=True)