All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Eduardo Habkost <ehabkost@redhat.com>
Cc: Marcel Apfelbaum <marcel@redhat.com>,
	Thomas Huth <thuth@redhat.com>,
	qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v3 2/3] qemu.py: Add QEMUMachine.exitcode() method
Date: Tue, 30 May 2017 07:25:25 +0200	[thread overview]
Message-ID: <87fufmuda2.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20170529170425.GG32274@thinpad.lan.raisama.net> (Eduardo Habkost's message of "Mon, 29 May 2017 14:04:25 -0300")

Eduardo Habkost <ehabkost@redhat.com> writes:

> On Mon, May 29, 2017 at 06:53:47PM +0200, Markus Armbruster wrote:
>> Eduardo Habkost <ehabkost@redhat.com> writes:
>> 
>> > Allow the exit code of QEMU to be queried by scripts.
>> >
>> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
>> > ---
>> >  scripts/qemu.py | 4 ++++
>> >  1 file changed, 4 insertions(+)
>> >
>> > diff --git a/scripts/qemu.py b/scripts/qemu.py
>> > index 16934f1e02..ebe1c4b919 100644
>> > --- a/scripts/qemu.py
>> > +++ b/scripts/qemu.py
>> > @@ -88,6 +88,10 @@ class QEMUMachine(object):
>> >      def is_running(self):
>> >          return self._popen and (self._popen.returncode is None)
>> >  
>> > +    def exitcode(self):
>> > +        if self._popen:
>> > +            return self._popen.returncode
>> > +
>> 
>> Falling off the function's end returns None.  Do we really want to rely
>> on that?
>> 
>> For what it's worth, I checked the Python Language Reference, found it
>> less than clear, so I tried it out, too.
>
> I agree that the intent may not be clear when looking at the
> code.  I can squash this in:
>
> diff --git a/scripts/qemu.py b/scripts/qemu.py
> index ebe1c4b919..bf00eddab8 100644
> --- a/scripts/qemu.py
> +++ b/scripts/qemu.py
> @@ -89,8 +89,9 @@ class QEMUMachine(object):
>          return self._popen and (self._popen.returncode is None)
>  
>      def exitcode(self):
> -        if self._popen:
> -            return self._popen.returncode
> +        if not self._popen:
> +            return None
> +        return self._popen.returncode
>  
>      def get_pid(self):
>          if not self.is_running():

Works for me.  The equivalent

    return self._popen and self._popen.returncode

would also work.  Nicely terse.

  reply	other threads:[~2017-05-30  5:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-26 18:11 [Qemu-devel] [PATCH v3 0/3] script for crash-testing -device Eduardo Habkost
2017-05-26 18:11 ` [Qemu-devel] [PATCH v3 1/3] qemu.py: Don't set _popen=None on error/shutdown Eduardo Habkost
2017-05-29 16:44   ` Markus Armbruster
2017-05-26 18:11 ` [Qemu-devel] [PATCH v3 2/3] qemu.py: Add QEMUMachine.exitcode() method Eduardo Habkost
2017-05-29 16:53   ` Markus Armbruster
2017-05-29 17:04     ` Eduardo Habkost
2017-05-30  5:25       ` Markus Armbruster [this message]
2017-05-26 18:12 ` [Qemu-devel] [PATCH v3 3/3] scripts: Test script to look for -device crashes Eduardo Habkost

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=87fufmuda2.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=marcel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.