* [RFC PATCH] python: add __repr__ to ConsoleSocket to aid debugging @ 2020-12-07 20:07 Alex Bennée 2020-12-07 21:02 ` John Snow 2020-12-07 21:35 ` Willian Rampazzo 0 siblings, 2 replies; 6+ messages in thread From: Alex Bennée @ 2020-12-07 20:07 UTC (permalink / raw) To: qemu-devel; +Cc: John Snow, Alex Bennée, Eduardo Habkost, Cleber Rosa 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 += ">" + return s + def _drain_fn(self) -> None: """Drains the socket and runs while the socket is open.""" while self._open: -- 2.20.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [RFC PATCH] python: add __repr__ to ConsoleSocket to aid debugging 2020-12-07 20:07 [RFC PATCH] python: add __repr__ to ConsoleSocket to aid debugging Alex Bennée @ 2020-12-07 21:02 ` John Snow 2020-12-07 21:35 ` Willian Rampazzo 1 sibling, 0 replies; 6+ messages in thread From: John Snow @ 2020-12-07 21:02 UTC (permalink / raw) To: Alex Bennée, qemu-devel; +Cc: Eduardo Habkost, Cleber Rosa On 12/7/20 3:07 PM, Alex Bennée 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): def __repr__(self) -> str: > + s = super(ConsoleSocket, self).__repr__() Use python3-style super(): super().__repr__() > + s = s.rstrip(">") > + s += ", logfile=%s" % (self._logfile) > + s += ", drain_thread=%s" % (self._drain_thread) > + s += ">" > + return s > + Reviewed-by: John Snow <jsnow@redhat.com> feel free to take this through your testing tree. --js ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC PATCH] python: add __repr__ to ConsoleSocket to aid debugging 2020-12-07 20:07 [RFC PATCH] python: add __repr__ to ConsoleSocket to aid debugging Alex Bennée 2020-12-07 21:02 ` John Snow @ 2020-12-07 21:35 ` Willian Rampazzo 2020-12-07 22:14 ` Philippe Mathieu-Daudé 2020-12-08 15:09 ` John Snow 1 sibling, 2 replies; 6+ messages in thread From: Willian Rampazzo @ 2020-12-07 21:35 UTC (permalink / raw) To: Alex Bennée; +Cc: Cleber Rosa, John Snow, qemu-devel, Eduardo Habkost 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 > > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC PATCH] python: add __repr__ to ConsoleSocket to aid debugging 2020-12-07 21:35 ` Willian Rampazzo @ 2020-12-07 22:14 ` Philippe Mathieu-Daudé 2020-12-07 23:14 ` Willian Rampazzo 2020-12-08 15:09 ` John Snow 1 sibling, 1 reply; 6+ messages in thread From: Philippe Mathieu-Daudé @ 2020-12-07 22:14 UTC (permalink / raw) To: Willian Rampazzo, Alex Bennée Cc: John Snow, qemu-devel, Eduardo Habkost, Cleber Rosa Hi Willian, On 12/7/20 10:35 PM, Willian Rampazzo wrote: > 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. With this (and John's comment) addressed, are you OK to add your R-b tag? > >> + return s >> + >> def _drain_fn(self) -> None: >> """Drains the socket and runs while the socket is open.""" >> while self._open: >> -- >> 2.20.1 >> >> > > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC PATCH] python: add __repr__ to ConsoleSocket to aid debugging 2020-12-07 22:14 ` Philippe Mathieu-Daudé @ 2020-12-07 23:14 ` Willian Rampazzo 0 siblings, 0 replies; 6+ messages in thread From: Willian Rampazzo @ 2020-12-07 23:14 UTC (permalink / raw) To: Philippe Mathieu-Daudé Cc: John Snow, Alex Bennée, qemu-devel, Eduardo Habkost, Cleber Rosa [-- Attachment #1: Type: text/plain, Size: 1939 bytes --] Em seg, 7 de dez de 2020 19:14, Philippe Mathieu-Daudé <philmd@redhat.com> escreveu: > Hi Willian, > > On 12/7/20 10:35 PM, Willian Rampazzo wrote: > > 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. > > With this (and John's comment) addressed, are you OK to add > your R-b tag? > Absolutely! The result will be the same in the end, so Reviewed-by: Willian Rampazzo <willianr@redhat.com> > > > >> + return s > >> + > >> def _drain_fn(self) -> None: > >> """Drains the socket and runs while the socket is open.""" > >> while self._open: > >> -- > >> 2.20.1 > >> > >> > > > > > > [-- Attachment #2: Type: text/html, Size: 3227 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC PATCH] python: add __repr__ to ConsoleSocket to aid debugging 2020-12-07 21:35 ` Willian Rampazzo 2020-12-07 22:14 ` Philippe Mathieu-Daudé @ 2020-12-08 15:09 ` John Snow 1 sibling, 0 replies; 6+ messages in thread From: John Snow @ 2020-12-08 15:09 UTC (permalink / raw) To: Willian Rampazzo, Alex Bennée Cc: qemu-devel, Eduardo Habkost, Cleber Rosa On 12/7/20 4:35 PM, Willian Rampazzo wrote: > 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. Sure, this is fine too. I'm not too worried about performance of debugging methods. Alex, use your own discretion -- feel free to keep my RB/ACK and merge alongside your other tests when ready. Thanks! --js ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-12-08 15:22 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2020-12-07 20:07 [RFC PATCH] python: add __repr__ to ConsoleSocket to aid debugging Alex Bennée 2020-12-07 21:02 ` John Snow 2020-12-07 21:35 ` Willian Rampazzo 2020-12-07 22:14 ` Philippe Mathieu-Daudé 2020-12-07 23:14 ` Willian Rampazzo 2020-12-08 15:09 ` John Snow
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).