All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: John Snow <jsnow@redhat.com>
Cc: qemu-devel <qemu-devel@nongnu.org>,
	Eduardo Habkost <eduardo@habkost.net>,
	Daniel Berrange <berrange@redhat.com>,
	Andrea Bolognani <abologna@redhat.com>,
	Wainer Moschetta <wainersm@redhat.com>,
	Beraldo Leal <bleal@redhat.com>, Kevin Wolf <kwolf@redhat.com>,
	Gerd Hoffmann <kraxel@redhat.com>,
	Hanna Reitz <hreitz@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	Cleber Rosa <crosa@redhat.com>,
	Qemu-block <qemu-block@nongnu.org>
Subject: Re: [PATCH v2 02/25] python/aqmp: handle asyncio.TimeoutError on execute()
Date: Thu, 16 Dec 2021 20:59:47 +0300	[thread overview]
Message-ID: <ceb2f83d-17aa-e1ae-465f-470e27f52aef@virtuozzo.com> (raw)
In-Reply-To: <CAFn=p-bCgLKP=4-o9PORrwpjH+gTQRRhF_+6gCp_wb6AqqZqyg@mail.gmail.com>

16.12.2021 20:22, John Snow wrote:
> 
> 
> On Thu, Dec 16, 2021 at 4:51 AM Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com <mailto:vsementsov@virtuozzo.com>> wrote:
> 
>     15.12.2021 22:39, John Snow wrote:
>      > This exception can be injected into any await statement. If we are
>      > canceled via timeout, we want to clear the pending execution record on
>      > our way out.
> 
>     Hmm, but there are more await statements in the file, shouldn't we care about them too ?
> 
> 
> Did any catch your eye? Depending on where it fails, it may not need any additional cleanup. In this case, it's important to delete the _pending entry so that we don't leave stale entries behind.

No. I simply searched for "await" reading the first sentence of commit message. Now I better follow what you are doing.

> 
>      >
>      > Signed-off-by: John Snow <jsnow@redhat.com <mailto:jsnow@redhat.com>>
>      > ---
>      >   python/qemu/aqmp/qmp_client.py | 8 ++++++--
>      >   1 file changed, 6 insertions(+), 2 deletions(-)
>      >
>      > diff --git a/python/qemu/aqmp/qmp_client.py b/python/qemu/aqmp/qmp_client.py
>      > index 8105e29fa8..6a985ffe30 100644
>      > --- a/python/qemu/aqmp/qmp_client.py
>      > +++ b/python/qemu/aqmp/qmp_client.py
>      > @@ -435,7 +435,11 @@ async def _issue(self, msg: Message) -> Union[None, str]:
>      >               msg_id = msg['id']
>      >
>      >           self._pending[msg_id] = asyncio.Queue(maxsize=1)
>      > -        await self._outgoing.put(msg)
>      > +        try:
>      > +            await self._outgoing.put(msg)
>      > +        except:
> 
>     Doesn't pylint and others complain about plain "except". Do we really need to catch any exception here? As far as I know that's not a good practice.
> 
> 
> pylint won't complain as long as you also ubiquitously re-raise the exception. It's only a bad practice to suppress all exceptions, but it's OK to define cleanup actions.
> 
>      > +            del self._pending[msg_id]
>      > +            raise
>      >
>      >           return msg_id
>      >
>      > @@ -452,9 +456,9 @@ async def _reply(self, msg_id: Union[str, None]) -> Message:
>      >               was lost, or some other problem.
>      >           """
>      >           queue = self._pending[msg_id]
>      > -        result = await queue.get()
>      >
>      >           try:
>      > +            result = await queue.get()
>      >               if isinstance(result, ExecInterruptedError):
>      >                   raise result
>      >               return result
>      >
> 
>     This one looks good, just include it into existing try-finally
> 
>     Hmm. _issue() and _reply() are used only in one place, as a pair. It looks like both "awaits" should be better under one try-finally block.
> 
> 
> They could. I split them for the sake of sub-classing if you wanted to perform additional actions on the outgoing/incoming arms of the execute() action. Specifically, I am accommodating the case that someone wants to subclass QMPClient and create methods where a QMP command is *sent* but is not *awaited*, i.e. _issue() is called without an immediate _reply(). This allows us the chance to create something like a PendingExecution object that could be awaited later on.
> 
> The simpler case, execute(), doesn't bother with separating those actions and just awaits the reply immediately.
> 
> 
>     For example, move "self._pending[msg_id] = asyncio.Queue(maxsize=1)" to _execute, and just do try-finally in _execute() around _issue and _reply. Or may be just merge the whole logic in _execute, it doesn't seem too much. What do you think?
> 


OK, that's all reasonable, thanks:
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>

-- 
Best regards,
Vladimir


  reply	other threads:[~2021-12-16 18:02 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-15 19:39 [PATCH v2 00/25] Python: delete synchronous qemu.qmp package John Snow
2021-12-15 19:39 ` [PATCH v2 01/25] python/aqmp: add __del__ method to legacy interface John Snow
2021-12-16  9:31   ` Vladimir Sementsov-Ogievskiy
2021-12-16 17:09     ` John Snow
2021-12-16 12:26   ` Beraldo Leal
2021-12-15 19:39 ` [PATCH v2 02/25] python/aqmp: handle asyncio.TimeoutError on execute() John Snow
2021-12-16  9:51   ` Vladimir Sementsov-Ogievskiy
2021-12-16 17:22     ` John Snow
2021-12-16 17:59       ` Vladimir Sementsov-Ogievskiy [this message]
2021-12-16 12:39   ` Beraldo Leal
2021-12-16 17:26     ` John Snow
2021-12-15 19:39 ` [PATCH v2 03/25] python/aqmp: copy type definitions from qmp John Snow
2021-12-16 10:00   ` Vladimir Sementsov-Ogievskiy
2021-12-16 10:19   ` Daniel P. Berrangé
2021-12-16 17:31     ` John Snow
2021-12-15 19:39 ` [PATCH v2 04/25] python/aqmp: add SocketAddrT to package root John Snow
2021-12-16 10:01   ` Vladimir Sementsov-Ogievskiy
2021-12-16 13:16   ` Beraldo Leal
2021-12-15 19:39 ` [PATCH v2 05/25] python/aqmp: rename AQMPError to QMPError John Snow
2021-12-16 10:08   ` Vladimir Sementsov-Ogievskiy
2021-12-16 17:01     ` John Snow
2021-12-15 19:39 ` [PATCH v2 06/25] python/qemu-ga-client: update instructions to newer CLI syntax John Snow
2021-12-16 10:14   ` Vladimir Sementsov-Ogievskiy
2021-12-16 17:36     ` John Snow
2021-12-16 10:16   ` Daniel P. Berrangé
2021-12-15 19:39 ` [PATCH v2 07/25] python/qmp: switch qemu-ga-client to AQMP John Snow
2021-12-16 10:31   ` Vladimir Sementsov-Ogievskiy
2021-12-16 17:43     ` John Snow
2021-12-16 13:21   ` Beraldo Leal
2021-12-15 19:39 ` [PATCH v2 08/25] python/qmp: switch qom tools " John Snow
2021-12-16 10:43   ` Vladimir Sementsov-Ogievskiy
2021-12-16 13:26   ` Beraldo Leal
2021-12-15 19:39 ` [PATCH v2 09/25] python/qmp: switch qmp-shell " John Snow
2021-12-16 10:45   ` Vladimir Sementsov-Ogievskiy
2021-12-15 19:39 ` [PATCH v2 10/25] python: move qmp utilities to python/qemu/utils John Snow
2021-12-16 10:48   ` Vladimir Sementsov-Ogievskiy
2021-12-15 19:39 ` [PATCH v2 11/25] python: move qmp-shell under the AQMP package John Snow
2021-12-16 10:49   ` Vladimir Sementsov-Ogievskiy
2021-12-16 13:31   ` Beraldo Leal
2021-12-15 19:39 ` [PATCH v2 12/25] python/machine: permanently switch to AQMP John Snow
2021-12-16 10:51   ` Vladimir Sementsov-Ogievskiy
2021-12-16 17:49     ` John Snow
2021-12-16 13:33   ` Beraldo Leal
2021-12-15 19:39 ` [PATCH v2 13/25] scripts/cpu-x86-uarch-abi: fix CLI parsing John Snow
2021-12-16 10:13   ` Daniel P. Berrangé
2021-12-16 10:55   ` Vladimir Sementsov-Ogievskiy
2021-12-15 19:39 ` [PATCH v2 14/25] scripts/cpu-x86-uarch-abi: switch to AQMP John Snow
2021-12-16 10:14   ` Daniel P. Berrangé
2021-12-16 10:56   ` Vladimir Sementsov-Ogievskiy
2021-12-16 13:46   ` Beraldo Leal
2021-12-15 19:39 ` [PATCH v2 15/25] scripts/render-block-graph: " John Snow
2021-12-16 10:57   ` Vladimir Sementsov-Ogievskiy
2021-12-16 20:48     ` John Snow
2021-12-16 13:47   ` Beraldo Leal
2021-12-15 19:39 ` [PATCH v2 16/25] scripts/bench-block-job: " John Snow
2021-12-16 10:58   ` Vladimir Sementsov-Ogievskiy
2021-12-16 13:49   ` Beraldo Leal
2021-12-15 19:39 ` [PATCH v2 17/25] iotests/mirror-top-perms: " John Snow
2021-12-16 11:01   ` Vladimir Sementsov-Ogievskiy
2021-12-16 13:50   ` Beraldo Leal
2021-12-15 19:39 ` [PATCH v2 18/25] iotests: " John Snow
2021-12-16 11:02   ` Vladimir Sementsov-Ogievskiy
2021-12-16 13:55   ` Beraldo Leal
2021-12-15 19:39 ` [PATCH v2 19/25] python: temporarily silence pylint duplicate-code warnings John Snow
2021-12-16 11:02   ` Vladimir Sementsov-Ogievskiy
2021-12-15 19:39 ` [PATCH v2 20/25] python/aqmp: take QMPBadPortError and parse_address from qemu.qmp John Snow
2021-12-16 11:05   ` Vladimir Sementsov-Ogievskiy
2021-12-16 14:03   ` Beraldo Leal
2021-12-15 19:39 ` [PATCH v2 21/25] python/aqmp: fully separate from qmp.QEMUMonitorProtocol John Snow
2021-12-16 11:11   ` Vladimir Sementsov-Ogievskiy
2021-12-16 14:11   ` Beraldo Leal
2021-12-15 19:39 ` [PATCH v2 22/25] python/aqmp: copy qmp docstrings to qemu.aqmp.legacy John Snow
2021-12-16 11:28   ` Vladimir Sementsov-Ogievskiy
2021-12-16 14:15   ` Beraldo Leal
2021-12-15 19:39 ` [PATCH v2 23/25] python: remove the old QMP package John Snow
2021-12-16 11:30   ` Vladimir Sementsov-Ogievskiy
2021-12-16 14:17   ` Beraldo Leal
2021-12-15 19:39 ` [PATCH v2 24/25] python: re-enable pylint duplicate-code warnings John Snow
2021-12-16 11:31   ` Vladimir Sementsov-Ogievskiy
2021-12-16 14:18   ` Beraldo Leal
2021-12-15 19:39 ` [PATCH v2 25/25] python: rename qemu.aqmp to qemu.qmp John Snow
2021-12-16 11:41   ` Vladimir Sementsov-Ogievskiy
2021-12-16 21:10     ` John Snow
2021-12-17  7:39       ` Vladimir Sementsov-Ogievskiy
2021-12-17 16:28         ` John Snow
2021-12-16 10:50 ` [PATCH v2 00/25] Python: delete synchronous qemu.qmp package Daniel P. Berrangé
2021-12-16 16:27   ` John Snow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ceb2f83d-17aa-e1ae-465f-470e27f52aef@virtuozzo.com \
    --to=vsementsov@virtuozzo.com \
    --cc=abologna@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=bleal@redhat.com \
    --cc=crosa@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=hreitz@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=wainersm@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.