The cause of the error, as it turns out, is that when -threadsresolved through
swig -threads -python test.i
We get something like this (redundant code has been edited):
PyObject *_wrap_Foo(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
PyObject *result = 0 ;
if (!PyArg_ParseTuple(args,(char *)":Foo")) SWIG_fail;
{
SWIG_PYTHON_THREAD_BEGIN_ALLOW;
result = (PyObject *)Foo();
SWIG_PYTHON_THREAD_END_ALLOW;
}
resultobj = result;
return resultobj;
fail:
return NULL;
}
static PyObject* Foo()
{
PyErr_SetNone(MyException);
return NULL;
}
See, when Foo () is called, an interpreter global lock is already issued. Foo () should no longer make any Python API calls.
, SWIG_Python_SetErrorObj, Global Interpreter API Python C.
static PyObject* Foo()
{
SWIG_Python_SetErrorObj(MyException, Py_None);
return NULL;
}
- SWIG_PYTHON_THREAD_BEGIN_BLOCK; SWIG_PYTHON_THREAD_END_BLOCK;
static PyObject* Foo()
{
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
PyErr_SetNone(MyException);
SWIG_PYTHON_THREAD_END_BLOCK;
return NULL;
}