aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett Brown <themagnificentmrb@gmail.com>2024-06-25 23:14:59 -0700
committerGarrett Brown <themagnificentmrb@gmail.com>2024-06-26 13:20:29 -0700
commit82982380e51dc2cb31533f548a40720339c7cfc3 (patch)
tree22aaca2a2966b569a01b8dc5156c96d9137b543b
parentc0161da767fad02f87be5746e377769fb0d0ebac (diff)
Python: Fix hang at application shutdown
-rw-r--r--xbmc/interfaces/python/XBPython.cpp6
1 files changed, 6 insertions, 0 deletions
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