From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37248) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YdimB-0005hE-5A for qemu-devel@nongnu.org; Thu, 02 Apr 2015 13:19:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ydim7-0003eo-Os for qemu-devel@nongnu.org; Thu, 02 Apr 2015 13:19:31 -0400 Message-ID: <551D7A1A.9050302@redhat.com> Date: Thu, 02 Apr 2015 13:19:22 -0400 From: John Snow MIME-Version: 1.0 References: <1426879023-18151-1-git-send-email-jsnow@redhat.com> <1426879023-18151-19-git-send-email-jsnow@redhat.com> <20150402135752.GM25244@stefanha-thinkpad.redhat.com> In-Reply-To: <20150402135752.GM25244@stefanha-thinkpad.redhat.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [Qemu-block] [PATCH v4 18/20] iotests: add QMP event waiting queue List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: famz@redhat.com, qemu-block@nongnu.org, qemu-devel@nongnu.org, armbru@redhat.com, vsementsov@parallels.com, stefanha@redhat.com, mreitz@redhat.com On 04/02/2015 09:57 AM, Stefan Hajnoczi wrote: > On Fri, Mar 20, 2015 at 03:17:01PM -0400, John Snow wrote: >> +# Test if 'match' is a recursive subset of 'event' >> +def event_match(event, match = None): > > Not worth respinning but PEP8 says there should be no spaces around the > '=' for keyword arguments: > https://www.python.org/dev/peps/pep-0008/#whitespace-in-expressions-and-statements > >> + def event_wait(self, name='BLOCK_JOB_COMPLETED', maxtries=3, match=None): >> + # Search cached events >> + for event in self._events: >> + if (event['event'] == name) and event_match(event, match): >> + self._events.remove(event) >> + return event >> + >> + # Poll for new events >> + for _ in range(maxtries): >> + event = self._qmp.pull_event(wait=True) >> + if (event['event'] == name) and event_match(event, match): >> + return event >> + self._events.append(event) >> + >> + return None > > I'm not sure if maxtries is useful. Why is a particular number of > skipped events useful to the caller and how do they pick the magic > number? > > If you added the argument because this is a blocking operation then we > should probably use timeouts instead. Timeouts will bail out even if > QEMU is unresponsive. > Yeah, this was just a poor man's timeout. I'll make it nicer.