MCPcopy
hub / github.com/pex-tool/pex / test_setproctitle

Function test_setproctitle

tests/integration/test_setproctitle.py:42–188  ·  view source on GitHub ↗
(
    tmpdir,  # type: Any
    venv,  # type: bool
    layout,  # type: Layout.Value
    installable_type,  # type: InstallableType.Value
)

Source from the content-addressed store, hash-verified

40 ],
41)
42def test_setproctitle(
43 tmpdir, # type: Any
44 venv, # type: bool
45 layout, # type: Layout.Value
46 installable_type, # type: InstallableType.Value
47):
48 # type: (...) -> None
49
50 pid_file = os.path.join(str(tmpdir), "pid")
51 os.mkfifo(pid_file)
52
53 src = os.path.join(str(tmpdir), "src")
54 with safe_open(os.path.join(src, "app.py"), "w") as fp:
55 fp.write(
56 dedent(
57 """\
58 from __future__ import print_function
59
60 import os
61 import threading
62
63 # Indicate PEX boot is complete and we've reached user code.
64 with open({pid_file!r}, "w") as fp:
65 print(str(os.getpid()), file=fp)
66
67 # Run forever to ensure there is time to read out our `ps` info.
68 cv = threading.Condition()
69 with cv:
70 cv.wait()
71 """.format(
72 pid_file=pid_file
73 )
74 )
75 )
76
77 build_pex_args = [
78 "-D",
79 src,
80 "-m",
81 "app",
82 "--layout",
83 layout.value,
84 get_installable_type_flag(installable_type),
85 ]
86 if venv:
87 build_pex_args.append("--venv")
88
89 def grab_ps(
90 pex, # type: str
91 *extra_pex_args # type: str
92 ):
93 # type: (...) -> Tuple[Text, Text]
94 run_pex_command(args=build_pex_args + ["-o", pex] + list(extra_pex_args)).assert_success()
95
96 process = subprocess.Popen(args=[sys.executable, pex, "--some", "arguments", "here"])
97 try:
98 # N.B.: We need to block on receiving the pid via fifo to prove that the PEX runtime has
99 # finished booting and completed any and all re-execs and landed in user code.

Callers

nothing calls this directly

Calls 9

safe_openFunction · 0.90
grab_psFunction · 0.85
assert_expected_pythonFunction · 0.85
appendMethod · 0.80
from_pexMethod · 0.80
joinMethod · 0.45
writeMethod · 0.45
venv_dirMethod · 0.45

Tested by

no test coverage detected