[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RFC PATCH] python: add __repr__ to ConsoleSocket to aid debugging
From: |
Willian Rampazzo |
Subject: |
Re: [RFC PATCH] python: add __repr__ to ConsoleSocket to aid debugging |
Date: |
Mon, 7 Dec 2020 18:35:14 -0300 |
On Mon, Dec 7, 2020 at 5:10 PM Alex Bennée <alex.bennee@linaro.org> wrote:
>
> While attempting to debug some console weirdness I thought it would be
> worth making it easier to see what it had inside.
>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
> python/qemu/console_socket.py | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/python/qemu/console_socket.py b/python/qemu/console_socket.py
> index f060d79e06..77966d1fe9 100644
> --- a/python/qemu/console_socket.py
> +++ b/python/qemu/console_socket.py
> @@ -45,6 +45,14 @@ class ConsoleSocket(socket.socket):
> if drain:
> self._drain_thread = self._thread_start()
>
> + def __repr__(self):
> + s = super(ConsoleSocket, self).__repr__()
> + s = s.rstrip(">")
> + s += ", logfile=%s" % (self._logfile)
> + s += ", drain_thread=%s" % (self._drain_thread)
> + s += ">"
We could use something more pythonic for this file. Instead of 3
string concatenations, my suggestion is to go with string formatting,
like:
s = "%s, logfile=%s, drain_thread=%s>" % (s, self._logfile, self._drain_thread)
As str is immutable in Python, it avoids unnecessary copies.
> + return s
> +
> def _drain_fn(self) -> None:
> """Drains the socket and runs while the socket is open."""
> while self._open:
> --
> 2.20.1
>
>