mirror of
https://gitlab.com/libvirt/libvirt-python.git
synced 2025-07-28 15:41:52 +03:00
event-test.py: Handle closed connection
If libvirtd terminates while event-test.py has an open connection to it, it will crash with the following traceback: > myConnectionCloseCallback: qemu:///session: Error > Exception in thread libvirtEventLoop: > Traceback (most recent call last): > File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner > self.run() > File "/usr/lib/python2.7/threading.py", line 754, in run > self.__target(*self.__args, **self.__kwargs) > File "examples/event-test.py", line 424, in virEventLoopPollRun > eventLoop.run_loop() > File "examples/event-test.py", line 242, in run_loop > self.run_once() > File "examples/event-test.py", line 187, in run_once > libvirt.virEventInvokeFreeCallback(opaque) > AttributeError: 'module' object has no attribute 'virEventInvokeFreeCallback' > > libvirt: XML-RPC error : internal error: client socket is closed > Traceback (most recent call last): > File "examples/event-test.py", line 872, in <module> > main() > File "examples/event-test.py", line 854, in main > vc.secretEventDeregisterAny(id) > File "/usr/lib/python2.7/dist-packages/libvirt.py", line 4987, in secretEventDeregisterAny > if ret == -1: raise libvirtError ('virConnectSecretEventDeregisterAny() failed', conn=self) > libvirt.libvirtError: internal error: client socket is closed > Closing qemu:///session Skip unregistering the event callbacks and closing the connection if the connection is already broken / closed. Signed-off-by: Philipp Hahn <hahn@univention.de>
This commit is contained in:
committed by
Michal Privoznik
parent
d5342a9803
commit
77e700c501
@ -716,7 +716,8 @@ def main():
|
||||
old_exitfunc = getattr(sys, 'exitfunc', None)
|
||||
def exit():
|
||||
print("Closing " + vc.getURI())
|
||||
vc.close()
|
||||
if run:
|
||||
vc.close()
|
||||
if (old_exitfunc): old_exitfunc()
|
||||
sys.exitfunc = exit
|
||||
|
||||
@ -777,6 +778,11 @@ def main():
|
||||
count = count + 1
|
||||
time.sleep(1)
|
||||
|
||||
# If the connection was closed, we cannot unregister anything.
|
||||
# Just abort now.
|
||||
if not run:
|
||||
return
|
||||
|
||||
vc.domainEventDeregister(myDomainEventCallback1)
|
||||
|
||||
for id in seccallbacks:
|
||||
|
Reference in New Issue
Block a user