On Wed, May 25, 2011 at 12:26 AM, Qingtang Zhou <[email protected]> wrote:
> monitor socket will be initiated at the beginning of '*Monitor.__init__',
> if exception occur in this function, socket will not be closed correctly.
> In this case, 'Monitor.__del__' function should be executed explicitly.

Calling an object internal method like this inside the code is bad
practice. We could do this better by:

1) Create a method called _close_socket(), thad does exactly what
__del__() is doing
2) make del call self._close_socket()
3) Use self._close_socket wherever you called __del__() on your patch

Would you please do this and send me an updated version? thanks!

> Signed-off-by: Qingtang Zhou <[email protected]>
> ---
>  client/virt/kvm_monitor.py |    5 +++++
>  1 files changed, 5 insertions(+), 0 deletions(-)
>
> diff --git a/client/virt/kvm_monitor.py b/client/virt/kvm_monitor.py
> index aff716a..7e97a3e 100644
> --- a/client/virt/kvm_monitor.py
> +++ b/client/virt/kvm_monitor.py
> @@ -171,6 +171,7 @@ class HumanMonitor(Monitor):
>             # Find the initial (qemu) prompt
>             s, o = self._read_up_to_qemu_prompt(20)
>             if not s:
> +                Monitor.__del__(self)
>                 raise MonitorProtocolError("Could not find (qemu) prompt "
>                                            "after connecting to monitor. "
>                                            "Output so far: %r" % o)
> @@ -179,6 +180,7 @@ class HumanMonitor(Monitor):
>             self._help_str = self.cmd("help", debug=False)
>
>         except MonitorError, e:
> +            Monitor.__del__(self)
>             if suppress_exceptions:
>                 logging.warn(e)
>             else:
> @@ -427,6 +429,7 @@ class QMPMonitor(Monitor):
>             try:
>                 json
>             except NameError:
> +                Monitor.__del__(self)
>                 raise MonitorNotSupportedError("QMP requires the json module "
>                                                "(Python 2.6 and up)")
>
> @@ -441,12 +444,14 @@ class QMPMonitor(Monitor):
>                     break
>                 time.sleep(0.1)
>             else:
> +                Monitor.__del__(self)
>                 raise MonitorProtocolError("No QMP greeting message received")
>
>             # Issue qmp_capabilities
>             self.cmd("qmp_capabilities")
>
>         except MonitorError, e:
> +            Monitor.__del__(self)
>             if suppress_exceptions:
>                 logging.warn(e)
>             else:
> --
> 1.7.4.1
>
> _______________________________________________
> Autotest mailing list
> [email protected]
> http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
>



-- 
Lucas
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to