Assigning sys.exitfunc no longer works with Python 3. Use atexit.register() instead. Signed-off-by: shechenglong <shechenglong@xfusion.com>
56 lines
1.5 KiB
Diff
56 lines
1.5 KiB
Diff
From cb8cceb0d8498bf0e2595a0830ab253afc3d64c7 Mon Sep 17 00:00:00 2001
|
|
From: Philipp Hahn <hahn@univention.de>
|
|
Date: Mon, 27 Apr 2020 14:57:04 +0200
|
|
Subject: [PATCH 001/297] 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>
|
|
---
|
|
examples/event-test.py | 8 +++-----
|
|
1 file changed, 3 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/examples/event-test.py b/examples/event-test.py
|
|
index 0bebf23..7a73da5 100755
|
|
--- a/examples/event-test.py
|
|
+++ b/examples/event-test.py
|
|
@@ -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.
|
|
@@ -776,16 +778,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)
|
|
|
|
--
|
|
2.38.1.windows.1
|
|
|