1

I am trying to use Jedi https://github.com/davidhalter/jedi to create a custom python editor and I am using c++, it works perfectly, but it is a bit slow and stalls for a small while, so I am calling those functions from inside a thread in c++, but doing so I am having a stack overflow error sometimes.

Here is my code:

//~ Create Script Instance class
PyObject* pScript = PyObject_Call(
                            PyObject_GetAttrString(GetJediModule(), "Script"),
                            PyTuple_Pack(1, PyString_FromString(TCHAR_TO_UTF8(*Source))), 
                            NULL);

if (pScript == NULL)
{
    UE_LOG(LogTemp, Verbose, TEXT("unable to get Script Class from Jedi Module"));
    Py_DECREF(pScript);
    ClearPython();
    return;
}

//~ Call complete method from Script Class
PyObject* Result = PyObject_Call(
                            PyObject_GetAttrString(pScript, "complete"), 
                            PyTuple_Pack(2, Py_BuildValue("i", Line), Py_BuildValue("i", Offset)), 
                            NULL);

if (Result == NULL)
{
    UE_LOG(LogTemp, Verbose, TEXT("unable to call complete method from Script class"));
    Py_DECREF(Result);
    ClearPython();
    return;
}

The error happens when call PyObject_Call, I assume is because the thread, since it works perfectly when I call the function from the main thread, but the stack is not telling me anything useful, just an error inside the python.dll

1 Answers1

1

Well I found the answer just by luck, it is possible to choose the stack size when I launch my thread in UE and I was using a super tiny value of 1024, I did a small modification and I have been testing for 3 hours without crashes anymore, so I guess is safe to assume is working now.

Here is how I setup the stack size, third arg is the stack size:

Thread = FRunnableThread::Create(this, TEXT("FAutoCompleteWorker"), 8 * 8 * 4096, TPri_Normal);
  • Thanks for finding this! Jedi indeed needs a stack that has a certain size, because it works with recursion a lot. – Dave Halter Aug 28 '20 at 08:05