Skip to content

Commit

Permalink
[fix] - let the scripts react on the abortRequest before killing them
Browse files Browse the repository at this point in the history
  • Loading branch information
Memphiz committed Feb 13, 2012
1 parent 0211f4a commit e6bf089
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions xbmc/interfaces/python/XBPyThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,13 @@ void XBPyThread::Process()
PyThreadState_Swap(NULL);
PyEval_ReleaseLock();

//set stopped event - this allows ::stop to run and kill remaining threads
//this event has to be fired without holding m_pExecuter->m_critSection
//before
//Also the GIL (PyEval_AcquireLock) must not be held
//if not obeyed there is still no deadlock because ::stop waits with timeout (smart one!)
stoppedEvent.Set();

{ CSingleLock lock(m_pExecuter->m_critSection);
m_threadState = NULL;
}
Expand Down Expand Up @@ -428,6 +435,17 @@ void XBPyThread::stop()
if(!m || PyObject_SetAttrString(m, (char*)"abortRequested", PyBool_FromLong(1)))
CLog::Log(LOGERROR, "XBPyThread::stop - failed to set abortRequested");

PyThreadState_Swap(old);
PyEval_ReleaseLock();

if(!stoppedEvent.WaitMSec(5000))//let the script 5 secs for shut stuff down
{
CLog::Log(LOGERROR, "XBPyThread::stop - script didn't stop in proper time - lets kill it");
}

//everything which didn't exit by now gets killed
PyEval_AcquireLock();
old = PyThreadState_Swap((PyThreadState*)m_threadState);
for(PyThreadState* state = ((PyThreadState*)m_threadState)->interp->tstate_head; state; state = state->next)
{
Py_XDECREF(state->async_exc);
Expand Down
2 changes: 2 additions & 0 deletions xbmc/interfaces/python/XBPyThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define XBPYTHREAD_H_

#include "threads/Thread.h"
#include "threads/Event.h"
#include "addons/IAddon.h"

class XBPython;
Expand All @@ -42,6 +43,7 @@ class XBPyThread : public CThread

protected:
XBPython *m_pExecuter;
CEvent stoppedEvent;
void *m_threadState;

char m_type;
Expand Down

2 comments on commit e6bf089

@Gujs
Copy link

@Gujs Gujs commented on e6bf089 Feb 21, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

I was just trying to implement this in openelec for its service addons. Will this be back-ported to Eden branch?

@Memphiz
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this will go into eden...

Please sign in to comment.