Skip to content

Commit 0eebd6d

Browse files
committed
Avoid deadlock in the ls_parse.py script
Python `subprocess.Popen.wait` deadlocks when using `stdout=subprocess.PIPE`, and the child process generates enough output to a pipe such that it blocks waiting for the OS pipe buffer to accept more data. See https://docs.python.org/3/library/subprocess.html#subprocess.Popen.wait. Spotted while trying to compile Xen `4.11`.
1 parent 88e3145 commit 0eebd6d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

scripts/ls_parse.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,9 @@ def symbols_from(object_file):
379379
cmd = ["objdump", "--syms", object_file]
380380
proc = subprocess.Popen(cmd, universal_newlines=True,
381381
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
382-
if proc.wait():
383-
logging.error("`%s` failed. Output:\n%s", " ".join(cmd),
384-
proc.stdout.read())
382+
proc_output, _ = proc.communicate()
383+
if proc.returncode:
384+
logging.error("`%s` failed. Output:\n%s", " ".join(cmd), proc_output)
385385
exit(1)
386386
pat = re.compile(r"(?P<addr>[^\s]+)\s+"
387387
r"(?P<flags>[lgu! ][w ][C ][W ][Ii ][Dd ][FfO ])\s+"
@@ -391,7 +391,7 @@ def symbols_from(object_file):
391391
)
392392
matching = False
393393
ret = {}
394-
for line in proc.stdout.read().splitlines():
394+
for line in proc_output.splitlines():
395395
if not line:
396396
continue
397397
if not matching and re.match("SYMBOL TABLE:", line):

0 commit comments

Comments
 (0)