mirror of
https://gitlab.com/libvirt/libvirt-python.git
synced 2025-08-03 08:21:58 +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:
committed by
Philipp Hahn
parent
59c2df2fa4
commit
cb8cceb0d8
@ -6,6 +6,7 @@
|
|||||||
# Start off by implementing a general purpose event loop for anyone's use
|
# Start off by implementing a general purpose event loop for anyone's use
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
|
import atexit
|
||||||
import sys
|
import sys
|
||||||
import getopt
|
import getopt
|
||||||
import os
|
import os
|
||||||
@ -15,6 +16,7 @@ import errno
|
|||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
|
||||||
# This example can use three different event loop impls. It defaults
|
# This example can use three different event loop impls. It defaults
|
||||||
# to a portable pure-python impl based on poll that is implemented
|
# to a portable pure-python impl based on poll that is implemented
|
||||||
# in this file.
|
# in this file.
|
||||||
@ -768,16 +770,12 @@ def main():
|
|||||||
vc = libvirt.openReadOnly(uri)
|
vc = libvirt.openReadOnly(uri)
|
||||||
|
|
||||||
# Close connection on exit (to test cleanup paths)
|
# Close connection on exit (to test cleanup paths)
|
||||||
old_exitfunc = getattr(sys, 'exitfunc', None)
|
|
||||||
|
|
||||||
def exit():
|
def exit():
|
||||||
print("Closing " + vc.getURI())
|
print("Closing " + vc.getURI())
|
||||||
if run:
|
if run:
|
||||||
vc.close()
|
vc.close()
|
||||||
if (old_exitfunc):
|
|
||||||
old_exitfunc()
|
|
||||||
|
|
||||||
sys.exitfunc = exit
|
atexit.register(exit)
|
||||||
|
|
||||||
vc.registerCloseCallback(myConnectionCloseCallback, None)
|
vc.registerCloseCallback(myConnectionCloseCallback, None)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user