From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 623BBC433FE for ; Mon, 7 Dec 2020 23:16:12 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CF230239FF for ; Mon, 7 Dec 2020 23:16:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CF230239FF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:54228 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kmPjm-0002gV-UH for qemu-devel@archiver.kernel.org; Mon, 07 Dec 2020 18:16:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46648) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmPiW-00029Q-VB for qemu-devel@nongnu.org; Mon, 07 Dec 2020 18:14:52 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:56945) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kmPiU-0006Pa-8H for qemu-devel@nongnu.org; Mon, 07 Dec 2020 18:14:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607382888; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=PqK/BI3IktDvwaYDL8l/vH0wDxFpJ2mEOcAJPKUBRUk=; b=dukuWHwWTtIrPFEr8bwR6rjfpAo2jgv3lwQEUdpbJOyz9USJmFTOhUu6Pw1QsVYsCvf4XA JOen1QLrppyVnID3z3SR6CRvavovh78L4dDUrceIq9LNfbO/dpAYjQQbuFqrfwrkAe6EvN IAU1cul1pNpD4gRz7JkRyFA2A8Y9A3I= Received: from mail-vk1-f198.google.com (mail-vk1-f198.google.com [209.85.221.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-258-8hSB6CIXO1KJwfx_lxRqwQ-1; Mon, 07 Dec 2020 18:14:46 -0500 X-MC-Unique: 8hSB6CIXO1KJwfx_lxRqwQ-1 Received: by mail-vk1-f198.google.com with SMTP id x134so6857088vkd.17 for ; Mon, 07 Dec 2020 15:14:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PqK/BI3IktDvwaYDL8l/vH0wDxFpJ2mEOcAJPKUBRUk=; b=JLURAOYRgPy2PwYf+5kRM8i/essHtyYmlk/oQoN1qacePqENTw4fFehG1NsA60IJyj uq71+pBISExPaV+8bRWB5URnoTvSPzY3jYzalokCxOr5/ZkWwSDAJsQ5FEN+TvpUHrk2 dvxa1KqJ3XpxGvj0o/OLB5aXUCSslhbaqjQU/ewijBEDR+aWsLR7ojOLwoJcjhG6+WMX aW+mEubCtGU5z3JcIHNFelEea35zuanopCMNWHGpy1rDsWiCb4jO8eJ17VERm9Niz79K DkZt/ydfYfjYKLCjC5fE6ZWxkco2l19+/b4V+A36/R2Fo8ZksRw6oDmcoZ5w/XGu6D6h NOkw== X-Gm-Message-State: AOAM532VhQMGhCoMP+cl7J54WBQB2kRep8qL9VS0wFYqn4h8x/pc3f8a rYT8ELBFDk3xf2plMIW00H9J+JrKPvbWzCNuQhAmvRewsGhKUej8EAlMbkVh8ZhLZVeryl4w/iY ffRAB6UT1I+rLBGZ+Q/2Rg9LjDiBE034= X-Received: by 2002:ab0:4306:: with SMTP id k6mr13690695uak.113.1607382885295; Mon, 07 Dec 2020 15:14:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJyGEkQJbGpt/Lw8hCYQTZvt0hDoG8aq4uWIyaG7IPtGyrDUw3yKzp4O5H9VzJoB19nAfXSIeTNeUI/qpdgmsVs= X-Received: by 2002:ab0:4306:: with SMTP id k6mr13690690uak.113.1607382885120; Mon, 07 Dec 2020 15:14:45 -0800 (PST) MIME-Version: 1.0 References: <20201207200737.5090-1-alex.bennee@linaro.org> <8a605a83-1be2-fd93-988f-4b70773e11d2@redhat.com> In-Reply-To: <8a605a83-1be2-fd93-988f-4b70773e11d2@redhat.com> From: Willian Rampazzo Date: Mon, 7 Dec 2020 20:14:35 -0300 Message-ID: Subject: Re: [RFC PATCH] python: add __repr__ to ConsoleSocket to aid debugging To: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=wrampazz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/alternative; boundary="000000000000e2d1d705b5e7fdc0" Received-SPF: pass client-ip=63.128.21.124; envelope-from=wrampazz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Snow , =?UTF-8?B?QWxleCBCZW5uw6ll?= , qemu-devel , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --000000000000e2d1d705b5e7fdc0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Em seg, 7 de dez de 2020 19:14, Philippe Mathieu-Daud=C3=A9 escreveu: > Hi Willian, > > On 12/7/20 10:35 PM, Willian Rampazzo wrote: > > On Mon, Dec 7, 2020 at 5:10 PM Alex Benn=C3=A9e > 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=C3=A9e > >> --- > >> 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 =3D self._thread_start() > >> > >> + def __repr__(self): > >> + s =3D super(ConsoleSocket, self).__repr__() > >> + s =3D s.rstrip(">") > >> + s +=3D ", logfile=3D%s" % (self._logfile) > >> + s +=3D ", drain_thread=3D%s" % (self._drain_thread) > >> + s +=3D ">" > > > > We could use something more pythonic for this file. Instead of 3 > > string concatenations, my suggestion is to go with string formatting, > > like: > > > > s =3D "%s, logfile=3D%s, drain_thread=3D%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 > > > >> + return s > >> + > >> def _drain_fn(self) -> None: > >> """Drains the socket and runs while the socket is open.""" > >> while self._open: > >> -- > >> 2.20.1 > >> > >> > > > > > > --000000000000e2d1d705b5e7fdc0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


Em seg, 7 de dez de 2020 19:14, Philippe Mathieu-Daud= =C3=A9 <philmd@redhat.com> e= screveu:
Hi Willian,

On 12/7/20 10:35 PM, Willian Rampazzo wrote:
> On Mon, Dec 7, 2020 at 5:10 PM Alex Benn=C3=A9e <alex.bennee@li= naro.org> wrote:
>>
>> While attempting to debug some console weirdness I thought it woul= d be
>> worth making it easier to see what it had inside.
>>
>> Signed-off-by: Alex Benn=C3=A9e <alex.bennee@linaro.org= >
>> ---
>>=C2=A0 python/qemu/console_socket.py | 8 ++++++++
>>=C2=A0 1 file changed, 8 insertions(+)
>>
>> diff --git a/python/qemu/console_socket.py b/python/qemu/console_s= ocket.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):
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if drain:
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 self._drain_thread= =3D self._thread_start()
>>
>> +=C2=A0 =C2=A0 def __repr__(self):
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 s =3D super(ConsoleSocket, self).__re= pr__()
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 s =3D s.rstrip(">")
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 s +=3D ", logfile=3D%s" % (= self._logfile)
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 s +=3D ", drain_thread=3D%s"= ; % (self._drain_thread)
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 s +=3D ">"
>
> We could use something more pythonic for this file. Instead of 3
> string concatenations, my suggestion is to go with string formatting,<= br> > like:
>
> s =3D "%s,=C2=A0 logfile=3D%s, drain_thread=3D%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>


>
>> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 return s
>> +
>>=C2=A0 =C2=A0 =C2=A0 def _drain_fn(self) -> None:
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 """Drains the soc= ket and runs while the socket is open."""
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 while self._open:
>> --
>> 2.20.1
>>
>>
>
>

--000000000000e2d1d705b5e7fdc0--