1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2025-07-29 19:41:52 +03:00

examples/event-test: Use atexit for Python 3

Assigning sys.exitfunc no longer works with Python 3.

Use atexit.register() instead.

Signed-off-by: Philipp Hahn <hahn@univention.de>
This commit is contained in:
Philipp Hahn
2020-04-27 14:57:04 +02:00
committed by Philipp Hahn
parent 59c2df2fa4
commit cb8cceb0d8

View File

@ -6,6 +6,7 @@
# Start off by implementing a general purpose event loop for anyone's use
##############################################################################
import atexit
import sys
import getopt
import os
@ -15,6 +16,7 @@ import errno
import time
import threading
# This example can use three different event loop impls. It defaults
# to a portable pure-python impl based on poll that is implemented
# in this file.
@ -768,16 +770,12 @@ def main():
vc = libvirt.openReadOnly(uri)
# Close connection on exit (to test cleanup paths)
old_exitfunc = getattr(sys, 'exitfunc', None)
def exit():
print("Closing " + vc.getURI())
if run:
vc.close()
if (old_exitfunc):
old_exitfunc()
sys.exitfunc = exit
atexit.register(exit)
vc.registerCloseCallback(myConnectionCloseCallback, None)