python: try to work without sub-interpreters
hopefully fixes crash in SWIG_MangledTypeQueryModule
@@ -159,11 +159,10 @@ static unsigned open_cnt = 0;
static void Python_Shutdown (moduleData * data)
{
- if (!data->shutdown) return;
-
/* destroy python if plugin isn't used anymore */
if (Py_IsInitialized ())
{
+ // Do we have a sub-interpreter?
if (data->tstate)
{
Python_LockSwap pylock (data->tstate);
@@ -207,6 +206,8 @@ int PYTHON_PLUGIN_FUNCTION (Open) (ckdb::Plugin * handle, ckdb::Key * errorKey)
* expected behaviour without worring about default values
*/
data->shutdown = (ksLookupByName (config, "/shutdown", 0) && !!strcmp (keyString (ksLookupByName (config, "/shutdown", 0)), "0"));
+ data->subinterpreter = (ksLookupByName (config, "/subinterpreter", 0) &&
+ !!strcmp (keyString (ksLookupByName (config, "/subinterpreter", 0)), "0"));
{
/* initialize python interpreter if necessary */
@@ -231,7 +232,11 @@ int PYTHON_PLUGIN_FUNCTION (Open) (ckdb::Plugin * handle, ckdb::Key * errorKey)
/* acquire GIL */
Python_LockSwap pylock (nullptr);
- /* create a new sub-interpreter */
+ if (data->subinterpreter)
+ {
+ /* Create a new sub-interpreter.
+ This is incompatible with PyGILState_Ensure, see directly above
+ https://docs.python.org/3/c-api/init.html#c.PyGILState_Ensure */
data->tstate = Py_NewInterpreter ();
if (data->tstate == nullptr)
{
@@ -239,6 +244,7 @@ int PYTHON_PLUGIN_FUNCTION (Open) (ckdb::Plugin * handle, ckdb::Key * errorKey)
goto error;
}
PyThreadState_Swap (data->tstate);
+ }
/* import kdb */
PyObject * kdbModule = PyImport_ImportModule ("kdb");
