Exemple #1
0
void XBPython::Finalize()
{
  if (m_bInitialized)
  {
    CLog::Log(LOGINFO, "Python, unloading python shared library because no scripts are running anymore");

    PyEval_AcquireLock();
    PyThreadState_Swap((PyThreadState*)m_mainThreadState);

    Py_Finalize();
    PyEval_ReleaseLock();

#if !(defined(__APPLE__) || defined(_WIN32))
    UnloadExtensionLibs();
#endif

    // first free all dlls loaded by python, after that python24.dll (this is done by UnloadPythonDlls
#if !(defined(__APPLE__) || defined(_WIN32))
    DllLoaderContainer::UnloadPythonDlls();
#endif
#if defined(_LINUX) && !defined(__APPLE__)
    // we can't release it on windows, as this is done in UnloadPythonDlls() for win32 (see above).
    // The implementation for linux needs looking at - UnloadPythonDlls() currently only searches for "python24.dll"
    // The implementation for osx can never unload the python dylib.
    DllLoaderContainer::ReleaseModule(m_pDll);
#endif
    m_hModule         = NULL;
    m_mainThreadState = NULL;
    m_bInitialized    = false;
  }
}
Exemple #2
0
/**
* Should be called when a script is finished
*/
void XBPython::Finalize()
{
  // for linux - we never release the library. its loaded and stays in memory.
  EnterCriticalSection(&m_critSection);
  m_iDllScriptCounter--;
  if (m_iDllScriptCounter == 0 && m_bInitialized)
  {
    CLog::Log(LOGINFO, "Python, unloading python24.dll cause no scripts are running anymore");
    PyEval_AcquireLock();
    PyThreadState_Swap(mainThreadState);
    Py_Finalize();

    UnloadExtensionLibs();

    //g_sectionLoader.UnloadDLL(PYTHON_DLL);
    // first free all dlls loaded by python, after that python24.dll (this is done by UnloadPythonDlls
    //dllFreeLibrary(m_hModule);
    DllLoaderContainer::UnloadPythonDlls();
#ifdef _LINUX
    DllLoaderContainer::ReleaseModule(m_pDll);
#endif    
    m_hModule = NULL;
    mainThreadState = NULL;
    
    m_bInitialized = false;
  }
  
  LeaveCriticalSection(&m_critSection);
}