01f9005feb
- Backport aqmp patches from upstream which can fix iotest issues * Patches added: python-aqmp-add-__del__-method-to-legacy.patch python-aqmp-add-_session_guard.patch python-aqmp-add-SocketAddrT-to-package-r.patch python-aqmp-add-socket-bind-step-to-lega.patch python-aqmp-add-start_server-and-accept-.patch python-aqmp-copy-type-definitions-from-q.patch python-aqmp-drop-_bind_hack.patch python-aqmp-fix-docstring-typo.patch python-aqmp-Fix-negotiation-with-pre-oob.patch python-aqmp-fix-race-condition-in-legacy.patch Python-aqmp-fix-type-definitions-for-myp.patch python-aqmp-handle-asyncio.TimeoutError-.patch python-aqmp-refactor-_do_accept-into-two.patch python-aqmp-remove-_new_session-and-_est.patch python-aqmp-rename-accept-to-start_serve.patch python-aqmp-rename-AQMPError-to-QMPError.patch python-aqmp-split-_client_connected_cb-o.patch python-aqmp-squelch-pylint-warning-for-t.patch python-aqmp-stop-the-server-during-disco.patch python-introduce-qmp-shell-wrap-convenie.patch python-machine-raise-VMLaunchFailure-exc.patch python-move-qmp-shell-under-the-AQMP-pac.patch python-move-qmp-utilities-to-python-qemu.patch python-qmp-switch-qmp-shell-to-AQMP.patch python-support-recording-QMP-session-to-.patch python-upgrade-mypy-to-0.780.patch - Drop the patches which are workaround to fix iotest issues * Patches dropped: Revert-python-iotests-replace-qmp-with-a.patch Revert-python-machine-add-instance-disam.patch Revert-python-machine-add-sock_dir-prope.patch Revert-python-machine-handle-fast-QEMU-t.patch Revert-python-machine-move-more-variable.patch Revert-python-machine-remove-_remove_mon.patch OBS-URL: https://build.opensuse.org/request/show/966963 OBS-URL: https://build.opensuse.org/package/show/Virtualization/qemu?expand=0&rev=708
65 lines
2.4 KiB
Diff
65 lines
2.4 KiB
Diff
From: John Snow <jsnow@redhat.com>
|
|
Date: Mon, 10 Jan 2022 18:28:45 -0500
|
|
Subject: python/aqmp: add __del__ method to legacy interface
|
|
|
|
Git-commit: 3bc72e3aed76e0326703db81964b13f1da075cbf
|
|
|
|
asyncio can complain *very* loudly if you forget to back out of things
|
|
gracefully before the garbage collector starts destroying objects that
|
|
contain live references to asyncio Tasks.
|
|
|
|
The usual fix is just to remember to call aqmp.disconnect(), but for the
|
|
sake of the legacy wrapper and quick, one-off scripts where a graceful
|
|
shutdown is not necessarily of paramount imporance, add a courtesy
|
|
cleanup that will trigger prior to seeing screenfuls of confusing
|
|
asyncio tracebacks.
|
|
|
|
Note that we can't *always* save you from yourself; depending on when
|
|
the GC runs, you might just seriously be out of luck. The best we can do
|
|
in this case is to gently remind you to clean up after yourself.
|
|
|
|
(Still much better than multiple pages of incomprehensible python
|
|
warnings for the crime of forgetting to put your toys away.)
|
|
|
|
Signed-off-by: John Snow <jsnow@redhat.com>
|
|
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
|
|
Reviewed-by: Beraldo Leal <bleal@redhat.com>
|
|
Signed-off-by: Li Zhang <lizhang@suse.de>
|
|
---
|
|
python/qemu/aqmp/legacy.py | 18 ++++++++++++++++++
|
|
1 file changed, 18 insertions(+)
|
|
|
|
diff --git a/python/qemu/aqmp/legacy.py b/python/qemu/aqmp/legacy.py
|
|
index 9e7b9fb80b95ad5d442fea0dbbab..2ccb136b02c1fcf586507400c056 100644
|
|
--- a/python/qemu/aqmp/legacy.py
|
|
+++ b/python/qemu/aqmp/legacy.py
|
|
@@ -16,6 +16,8 @@ from typing import (
|
|
import qemu.qmp
|
|
from qemu.qmp import QMPMessage, QMPReturnValue, SocketAddrT
|
|
|
|
+from .error import AQMPError
|
|
+from .protocol import Runstate
|
|
from .qmp_client import QMPClient
|
|
|
|
|
|
@@ -136,3 +138,19 @@ class QEMUMonitorProtocol(qemu.qmp.QEMUMonitorProtocol):
|
|
|
|
def send_fd_scm(self, fd: int) -> None:
|
|
self._aqmp.send_fd_scm(fd)
|
|
+
|
|
+ def __del__(self) -> None:
|
|
+ if self._aqmp.runstate == Runstate.IDLE:
|
|
+ return
|
|
+
|
|
+ if not self._aloop.is_running():
|
|
+ self.close()
|
|
+ else:
|
|
+ # Garbage collection ran while the event loop was running.
|
|
+ # Nothing we can do about it now, but if we don't raise our
|
|
+ # own error, the user will be treated to a lot of traceback
|
|
+ # they might not understand.
|
|
+ raise AQMPError(
|
|
+ "QEMUMonitorProtocol.close()"
|
|
+ " was not called before object was garbage collected"
|
|
+ )
|