Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[fix] - let the scripts react on the abortRequest before killing them

  • Loading branch information...
commit e6bf089bbf486c9879d3abc5ce31a99b67558ea7 1 parent 0211f4a
@Memphiz Memphiz authored
View
18 xbmc/interfaces/python/XBPyThread.cpp
@@ -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;
}
@@ -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);
View
2  xbmc/interfaces/python/XBPyThread.h
@@ -23,6 +23,7 @@
#define XBPYTHREAD_H_
#include "threads/Thread.h"
+#include "threads/Event.h"
#include "addons/IAddon.h"
class XBPython;
@@ -42,6 +43,7 @@ class XBPyThread : public CThread
protected:
XBPython *m_pExecuter;
+ CEvent stoppedEvent;
void *m_threadState;
char m_type;

2 comments on commit e6bf089

@Gujs

Hi,

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

@Memphiz
Owner

Yes this will go into eden...

Please sign in to comment.
Something went wrong with that request. Please try again.