From b522aed82d12ec5d420f7a41ecddbb3d14ff90bf Mon Sep 17 00:00:00 2001 From: Andry Ogorodnik Date: Tue, 15 May 2018 18:34:50 +0300 Subject: [PATCH] R406-026 Preventing python finalization error Change-Id: I163227331c3295b94a4d2c0cc047a1210908126b --- python/src/python_module.adb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/python/src/python_module.adb b/python/src/python_module.adb index 22118663f9..65d7215c09 100644 --- a/python/src/python_module.adb +++ b/python/src/python_module.adb @@ -747,7 +747,25 @@ package body Python_Module is ------------- overriding procedure Destroy (Module : in out Python_Module_Record) is + Script : constant Scripting_Language := + Get_Kernel (Module).Scripts.Lookup_Scripting_Language (Python_Name); + Errors : aliased Boolean; + Result : PyObject; begin + -- Importing jedi (versions 0.9, 0.12) raises "Error in sys.exitfunc" + -- in console if future 0.16 is installed because of some exception + -- when python is finalizing. Following code prevent this. + + Result := Run_Command + (Python_Scripting (Script), + "import atexit ; atexit._run_exitfuncs()", + Need_Output => False, + Show_Command => False, + Hide_Output => True, + Hide_Exceptions => True, + Errors => Errors'Unchecked_Access); + Py_XDECREF (Result); + Unregister_Python_Scripting (Get_Kernel (Module).Scripts); end Destroy;