MCPcopy Create free account
hub / github.com/bloomberg/pystack / generate_core_file

Function generate_core_file

tests/utils.py:114–143  ·  view source on GitHub ↗
(
    python: pathlib.Path, test_file: pathlib.Path, tmpdir: pathlib.Path
)

Source from the content-addressed store, hash-verified

112
113@contextlib.contextmanager
114def generate_core_file(
115 python: pathlib.Path, test_file: pathlib.Path, tmpdir: pathlib.Path
116) -> Generator[pathlib.Path, None, None]:
117 fifo = tmpdir / "the_fifo"
118 os.mkfifo(fifo)
119 with subprocess.Popen(
120 [python, test_file, str(fifo)],
121 stdout=subprocess.PIPE,
122 stderr=subprocess.PIPE,
123 ) as process:
124 with open(fifo, "r") as fifo_file:
125 response = fifo_file.read()
126
127 assert response == "ready"
128 subprocess.run(
129 ["gcore", str(process.pid)],
130 check=True,
131 stdout=subprocess.PIPE,
132 stderr=subprocess.PIPE,
133 cwd=str(tmpdir),
134 text=True,
135 )
136 (core,) = pathlib.Path(tmpdir).glob("core.*")
137 try:
138 yield core
139 finally:
140 os.remove(fifo)
141 process.terminate()
142 process.kill()
143 process.wait(timeout=TIMEOUT)
144
145
146@contextlib.contextmanager

Calls

no outgoing calls