]> git.phdru.name Git - dotfiles.git/commitdiff
Feat(python/init): Py2 and 3 have different ways to clear exit handlers
authorOleg Broytman <phd@phdru.name>
Thu, 21 Aug 2025 17:11:39 +0000 (20:11 +0300)
committerOleg Broytman <phd@phdru.name>
Thu, 21 Aug 2025 17:11:39 +0000 (20:11 +0300)
lib/python/init.py

index 4bd52581da2d5f07ee33d8914854f869ffbb078b..da4808038b7597187c6a04dcad63f11fba1584ae 100644 (file)
@@ -64,10 +64,18 @@ def init():
         import atexit
         atexit.register(savehist)
 
-        def unset_history():
-            import atexit
-            atexit._exithandlers = []
-        builtins.unset_history = unset_history
+        if hasattr(atexit, '_exithandlers'):
+            def unset_history2():
+                import atexit
+                atexit._exithandlers = []
+            builtins.unset_history = unset_history2
+        elif hasattr(atexit, '_clear') and callable(atexit._clear):
+            def unset_history3():
+                import atexit
+                atexit._clear()
+            builtins.unset_history = unset_history3
+        else:
+            sys.stderr.write('Error: cannot clear exit handlers\n')
 
     except (ImportError, AttributeError):
         # no readline or atexit, or readline doesn't have