Skip to content
Snippets Groups Projects
Commit b1b20ea9 authored by vlorentz's avatar vlorentz
Browse files

shell: Fix hangs in pytest

For some reason, this now happens all the time on my machine.

This may also be the cause of the random hangs we have had on Jenkins
parent f54c2837
No related branches found
No related tags found
1 merge request!706shell: Fix hangs in pytest
Pipeline #12734 passed
......@@ -371,10 +371,13 @@ class Pipe:
def _run(self, stdin, stdout) -> _RunningPipe:
read_pipes: List[Any] = [stdin]
write_pipes: List[Any] = []
pipes_to_close: List[int] = []
for _ in range(len(self.children) - 1):
(r, w) = os.pipe()
read_pipes.append(os.fdopen(r, "rb"))
write_pipes.append(os.fdopen(w, "wb"))
pipes_to_close.append(r)
pipes_to_close.append(w)
write_pipes.append(stdout)
running_children = [
......@@ -382,6 +385,18 @@ class Pipe:
for (r, w, child) in zip(read_pipes, write_pipes, self.children)
]
# We need to close these file descriptors in the parent process, so that the
# corresponding pipes have an end fully closed when the corresponding process
# dies.
# On CPython (and when not running in tools like pytest that keep references to
# call frames), this would be done automatically when the function exits because
# the refcount to all pipes becomes 0, but we cannot rely
# on this behavior.
# Without it, the other end of the process will hang when trying to read
# or write to it.
for pipe in pipes_to_close:
os.close(pipe)
return _RunningPipe(self, running_children)
def run(self) -> None:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment