From 82982380e51dc2cb31533f548a40720339c7cfc3 Mon Sep 17 00:00:00 2001 From: Garrett Brown Date: Tue, 25 Jun 2024 23:14:59 -0700 Subject: Python: Fix hang at application shutdown --- xbmc/interfaces/python/XBPython.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xbmc/interfaces/python/XBPython.cpp b/xbmc/interfaces/python/XBPython.cpp index 7498c14ebb..5fdd17610f 100644 --- a/xbmc/interfaces/python/XBPython.cpp +++ b/xbmc/interfaces/python/XBPython.cpp @@ -57,7 +57,13 @@ XBPython::~XBPython() #if PY_VERSION_HEX >= 0x03070000 if (Py_IsInitialized()) { + // Switch to the main interpreter thread before finalizing PyThreadState_Swap(PyInterpreterState_ThreadHead(PyInterpreterState_Main())); + + // Clear all loaded modules to prevent circular references + PyObject* modules = PyImport_GetModuleDict(); + PyDict_Clear(modules); + Py_Finalize(); } #endif -- cgit v1.2.3