Skip to content

Commit 4943897

Browse files
XanClickevmw
authored andcommitted
iotests.py: Do not wait() before communicate()
Waiting on a process for which we have a pipe will stall if the process outputs more data than fits into the OS-provided buffer. We must use communicate() before wait(), and in fact, communicate() perfectly replaces wait() already. We have to drop the stderr=subprocess.STDOUT parameter from subprocess.Popen() in qemu_nbd_early_pipe(), because stderr is passed on to the child process, so if we do not drop this parameter, communicate() will hang (because the pipe is not closed). Signed-off-by: Max Reitz <[email protected]> Message-Id: <[email protected]> Signed-off-by: Kevin Wolf <[email protected]>
1 parent 3dfa23b commit 4943897

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

tests/qemu-iotests/iotests.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,12 @@ def qemu_img_pipe(*args):
146146
stdout=subprocess.PIPE,
147147
stderr=subprocess.STDOUT,
148148
universal_newlines=True)
149-
exitcode = subp.wait()
150-
if exitcode < 0:
149+
output = subp.communicate()[0]
150+
if subp.returncode < 0:
151151
sys.stderr.write('qemu-img received signal %i: %s\n'
152-
% (-exitcode, ' '.join(qemu_img_args + list(args))))
153-
return subp.communicate()[0]
152+
% (-subp.returncode,
153+
' '.join(qemu_img_args + list(args))))
154+
return output
154155

155156
def qemu_img_log(*args):
156157
result = qemu_img_pipe(*args)
@@ -177,11 +178,11 @@ def qemu_io(*args):
177178
subp = subprocess.Popen(args, stdout=subprocess.PIPE,
178179
stderr=subprocess.STDOUT,
179180
universal_newlines=True)
180-
exitcode = subp.wait()
181-
if exitcode < 0:
181+
output = subp.communicate()[0]
182+
if subp.returncode < 0:
182183
sys.stderr.write('qemu-io received signal %i: %s\n'
183-
% (-exitcode, ' '.join(args)))
184-
return subp.communicate()[0]
184+
% (-subp.returncode, ' '.join(args)))
185+
return output
185186

186187
def qemu_io_log(*args):
187188
result = qemu_io(*args)
@@ -257,15 +258,14 @@ def qemu_nbd_early_pipe(*args):
257258
and its output in case of an error'''
258259
subp = subprocess.Popen(qemu_nbd_args + ['--fork'] + list(args),
259260
stdout=subprocess.PIPE,
260-
stderr=subprocess.STDOUT,
261261
universal_newlines=True)
262-
exitcode = subp.wait()
263-
if exitcode < 0:
262+
output = subp.communicate()[0]
263+
if subp.returncode < 0:
264264
sys.stderr.write('qemu-nbd received signal %i: %s\n' %
265-
(-exitcode,
265+
(-subp.returncode,
266266
' '.join(qemu_nbd_args + ['--fork'] + list(args))))
267267

268-
return exitcode, subp.communicate()[0] if exitcode else ''
268+
return subp.returncode, output if subp.returncode else ''
269269

270270
def qemu_nbd_popen(*args):
271271
'''Run qemu-nbd in daemon mode and return the parent's exit code'''
@@ -1062,11 +1062,11 @@ def qemu_pipe(*args):
10621062
subp = subprocess.Popen(args, stdout=subprocess.PIPE,
10631063
stderr=subprocess.STDOUT,
10641064
universal_newlines=True)
1065-
exitcode = subp.wait()
1066-
if exitcode < 0:
1065+
output = subp.communicate()[0]
1066+
if subp.returncode < 0:
10671067
sys.stderr.write('qemu received signal %i: %s\n' %
1068-
(-exitcode, ' '.join(args)))
1069-
return subp.communicate()[0]
1068+
(-subp.returncode, ' '.join(args)))
1069+
return output
10701070

10711071
def supported_formats(read_only=False):
10721072
'''Set 'read_only' to True to check ro-whitelist

0 commit comments

Comments
 (0)