From 841277f7e10f38a2d2366a4bc948610b1ab8e8a9 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Thu, 21 Aug 2025 20:11:39 +0300 Subject: [PATCH] Feat(python/init): Py2 and 3 have different ways to clear exit handlers --- lib/python/init.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/python/init.py b/lib/python/init.py index 4bd5258..da48080 100644 --- a/lib/python/init.py +++ b/lib/python/init.py @@ -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 -- 2.39.5