PYA to support multiple python interpreter

edited June 2017 in General

We use to embed c++ with Python. So that C++ with some python API can be launched by Python process. We also run with multithread, each thread will launch a python interpreter.

Every time, the program runs fine when we have less than 16 threads running. As long as there is 16 or more threads, job will have segfault when exiting the program.

some information from the core:

#0 0x00000000015ee36b in type_dealloc (type=0x2481820) at Objects/typeobject.c:2985
#1 0x00000000015ee627 in type_dealloc (type=0x7fc2541b3498) at Objects/typeobject.c:2991
#2 0x0000000001688a0a in delete_garbage (generation=2, n_collected=0x0, n_uncollectable=0x0, nofail=1) at Modules/gcmodule.c:867
#3 collect (generation=2, n_collected=0x0, n_uncollectable=0x0, nofail=1) at Modules/gcmodule.c:1032
#4 0x0000000001688f0d in _PyGC_CollectNoFail () at Modules/gcmodule.c:1638
#5 0x000000000165e48f in PyImport_Cleanup () at Python/import.c:487
#6 0x000000000166d1fe in Py_EndInterpreter (tstate=0x7fc254020ea0) at Python/pythonrun.c:868
#7 0x00000000013b457f in pya::PythonInterpreter::~PythonInterpreter() ()
#8 0x00000000013b4ca9 in pya::PythonInterpreter::~PythonInterpreter() ()
#9 0x0000000001261546 in gsi::Application::~Application() ()

We are using python 3.4

DO you have any clue for this?



  • edited November -1

    Hi werk,

    what precisely are you doing? You mean, you are using for your own project?

    Running Python in separate native threads is not supported AFAIK (at least not with CPython - JPython or IronPython can do this. But maybe that changed with recent CPython's). If you want to do this, you have to properly lock and unlock the global interpreter lock. is not equipped with the necessary PyGILState_Ensure and PyGILState_Released calls since KLayout uses it's own mutexes.

    It can be extended to do this, but what precisely for?


Sign In or Register to comment.