MCPcopy Create free account
hub / github.com/Sigil-Ebook/Sigil / addToPythonSysPath

Method addToPythonSysPath

src/EmbedPython/EmbeddedPython.cpp:353–375  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

351}
352
353bool EmbeddedPython::addToPythonSysPath(const QString &mpath)
354{
355 EmbeddedPython::m_mutex.lock();
356 PyGILState_STATE gstate = PyGILState_Ensure();
357
358 PyObject* sysPath = NULL;
359 PyObject* aPath = NULL;
360 bool success = false;
361
362 // PySys_GetObject borrows a reference */
363 sysPath = PySys_GetObject((char*)"path");
364 if (sysPath != NULL) {
365 aPath = PyUnicode_FromString(mpath.toUtf8().constData());
366 if (aPath != NULL) {
367 PyList_Append(sysPath, aPath);
368 success = true;
369 }
370 }
371 Py_XDECREF(aPath);
372 PyGILState_Release(gstate);
373 EmbeddedPython::m_mutex.unlock();
374 return success;
375}
376
377// run interpreter without initiating/locking/unlocking GIL
378// in a single thread at a time

Callers 1

mainFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected