• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisão3bc72e3aed76e0326703db81964b13f1da075cbf (tree)
Hora2022-01-22 06:01:31
AutorJohn Snow <jsnow@redh...>
CommiterJohn Snow

Mensagem de Log

python/aqmp: add del method to legacy interface

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>

Mudança Sumário

Diff

--- a/python/qemu/aqmp/legacy.py
+++ b/python/qemu/aqmp/legacy.py
@@ -16,6 +16,8 @@ from typing import (
1616 import qemu.qmp
1717 from qemu.qmp import QMPMessage, QMPReturnValue, SocketAddrT
1818
19+from .error import AQMPError
20+from .protocol import Runstate
1921 from .qmp_client import QMPClient
2022
2123
@@ -136,3 +138,19 @@ class QEMUMonitorProtocol(qemu.qmp.QEMUMonitorProtocol):
136138
137139 def send_fd_scm(self, fd: int) -> None:
138140 self._aqmp.send_fd_scm(fd)
141+
142+ def __del__(self) -> None:
143+ if self._aqmp.runstate == Runstate.IDLE:
144+ return
145+
146+ if not self._aloop.is_running():
147+ self.close()
148+ else:
149+ # Garbage collection ran while the event loop was running.
150+ # Nothing we can do about it now, but if we don't raise our
151+ # own error, the user will be treated to a lot of traceback
152+ # they might not understand.
153+ raise AQMPError(
154+ "QEMUMonitorProtocol.close()"
155+ " was not called before object was garbage collected"
156+ )