diff options
author | Garrett Brown <themagnificentmrb@gmail.com> | 2024-06-27 15:02:21 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-27 15:02:21 -0700 |
commit | 402d10442eab03cd39ef154ff7ee1a41eae5fc3d (patch) | |
tree | fbe2f63f70944dd8ac6b14a1cf8144ea16eecdf8 | |
parent | 253db04ded8b13ef8c610fcd4a4d4109cff27236 (diff) | |
parent | 82982380e51dc2cb31533f548a40720339c7cfc3 (diff) |
Merge pull request #25382 from garbear/fix-python-hang
Python: Fix hang at application shutdown
-rw-r--r-- | xbmc/interfaces/python/XBPython.cpp | 6 |
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 |