python/aqmp: add _session_guard()
commit40196c23939758abc5300e85333e676196e3ba6d
authorJohn Snow <jsnow@redhat.com>
Fri, 25 Feb 2022 20:59:39 +0000 (25 15:59 -0500)
committerJohn Snow <jsnow@redhat.com>
Mon, 7 Mar 2022 19:36:41 +0000 (7 14:36 -0500)
treebe0c62a938ac3e9750fea7dd356c433adf5c95c3
parentb49872aa8fc0f3f5a3036cc37aa2cb5c92866f33
python/aqmp: add _session_guard()

In _new_session, there's a fairly complex except clause that's used to
give semantic errors to callers of accept() and connect(). We need to
create a new two-step replacement for accept(), so factoring out this
piece of logic will be useful.

Bolster the comments and docstring here to try and demystify what's
going on in this fairly delicate piece of Python magic.

(If we were using Python 3.7+, this would be an @asynccontextmanager. We
don't have that very nice piece of magic, however, so this must take an
Awaitable to manage the Exception contexts properly. We pay the price
for platform compatibility.)

Signed-off-by: John Snow <jsnow@redhat.com>
Acked-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-id: 20220225205948.3693480-2-jsnow@redhat.com
Signed-off-by: John Snow <jsnow@redhat.com>
python/qemu/aqmp/protocol.py