Skip to content

Commit

Permalink
Merge pull request #18305 from enen92/stopallscripts
Browse files Browse the repository at this point in the history
[python] Stop any running scripts on shutdown
  • Loading branch information
enen92 committed Aug 25, 2020
2 parents 943faf8 + d042659 commit f80d155
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions xbmc/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2679,6 +2679,9 @@ void CApplication::Stop(int exitCode)
// Stop services before unloading Python
CServiceBroker::GetServiceAddons().Stop();

// Stop any other python scripts that may be looping waiting for monitor.abortRequested()
CScriptInvocationManager::GetInstance().StopRunningScripts();

// unregister action listeners
UnregisterActionListener(&m_appPlayer.GetSeekHandler());
UnregisterActionListener(&CPlayerController::GetInstance());
Expand Down
9 changes: 9 additions & 0 deletions xbmc/interfaces/generic/ScriptInvocationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,15 @@ bool CScriptInvocationManager::Stop(int scriptId, bool wait /* = false */)
return invokerThread->Stop(wait);
}

void CScriptInvocationManager::StopRunningScripts(bool wait /* = false */)
{
for (auto& it : m_scripts)
{
if (!it.second.done)
Stop(it.second.script, wait);
}
}

bool CScriptInvocationManager::Stop(const std::string &scriptPath, bool wait /* = false */)
{
if (scriptPath.empty())
Expand Down
6 changes: 6 additions & 0 deletions xbmc/interfaces/generic/ScriptInvocationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ class CScriptInvocationManager
bool Stop(int scriptId, bool wait = false);
bool Stop(const std::string &scriptPath, bool wait = false);

/*!
*\brief Stop all running scripts
*\param wait if kodi should wait for each script to finish (default false)
*/
void StopRunningScripts(bool wait = false);

bool IsRunning(int scriptId) const;
bool IsRunning(const std::string& scriptPath) const;

Expand Down

0 comments on commit f80d155

Please sign in to comment.