qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v3 2/3] qemu.py: Add QEMUMachine.exitcode() meth


From: Markus Armbruster
Subject: Re: [Qemu-devel] [PATCH v3 2/3] qemu.py: Add QEMUMachine.exitcode() method
Date: Tue, 30 May 2017 07:25:25 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)

Eduardo Habkost <address@hidden> writes:

> On Mon, May 29, 2017 at 06:53:47PM +0200, Markus Armbruster wrote:
>> Eduardo Habkost <address@hidden> writes:
>> 
>> > Allow the exit code of QEMU to be queried by scripts.
>> >
>> > Signed-off-by: Eduardo Habkost <address@hidden>
>> > ---
>> >  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 via email to

[Prev in Thread] Current Thread [Next in Thread]