From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 2/3] scripts/qemu: Catch QEMU exit while waiting for QMP client
Date: Tue, 13 Jun 2017 20:06:26 -0300 [thread overview]
Message-ID: <20170613230627.17942-3-ehabkost@redhat.com> (raw)
In-Reply-To: <20170613230627.17942-1-ehabkost@redhat.com>
To avoid waiting for the full 15-second timeout for a connection, check
if QEMU exited once in a while. Start with a very short timeout (15ms),
and double it on each try.
This will be helpful for scripts/device-crash-test, on cases where QEMU
crashes or exits before connecting to the QMP socket.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
scripts/qemu.py | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/scripts/qemu.py b/scripts/qemu.py
index 880e3e8219..5416bcfef9 100644
--- a/scripts/qemu.py
+++ b/scripts/qemu.py
@@ -17,6 +17,7 @@ import string
import os
import sys
import subprocess
+import socket
import qmp.qmp
@@ -118,7 +119,18 @@ class QEMUMachine(object):
debug=self._debug)
def _post_launch(self):
- self._qmp.accept()
+ # Wait for a connection while checking if QEMU is still running:
+ timeout = 0.015
+ tries = 10 # 0.015*2**10 = ~15 seconds
+ for i in range(tries):
+ try:
+ self._qmp.accept(timeout=timeout)
+ break
+ except socket.timeout:
+ if self._popen.poll():
+ raise Exception("QEMU terminated before connecting to QMP")
+ # wait a little longer on the next try:
+ timeout *= 2
def _post_shutdown(self):
if not isinstance(self._monitor_address, tuple):
--
2.11.0.259.g40922b1
next prev parent reply other threads:[~2017-06-13 23:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-13 23:06 [Qemu-devel] [PATCH 0/3] device-crash-test: New mode for testing -object Eduardo Habkost
2017-06-13 23:06 ` [Qemu-devel] [PATCH 1/3] scripts/qmp: Accept timeout parameter on accept() Eduardo Habkost
2017-06-13 23:06 ` Eduardo Habkost [this message]
2017-06-13 23:06 ` [Qemu-devel] [PATCH 3/3] device-crash-test: Mode for testing -object Eduardo Habkost
2017-06-13 23:20 ` [Qemu-devel] [PATCH 0/3] device-crash-test: New mode " no-reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170613230627.17942-3-ehabkost@redhat.com \
--to=ehabkost@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).