You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
hello.
i have embedded python, using pybind11, and then call cppyy with a simple c++ program. it works fine when calling the simple python script once, but call it again and it fails. here is the code (function):
"//
void Test002()
{
//
py::scoped_interpreter guard{};
//
QString qPythonDir("/home/simon/Code/QT/Test_pybind11/Test_pybind11_cppyy_001/");
QString qPythonCommand("");
//
auto locals = py::dict();
auto globals = py::dict();
//
qPythonCommand += "import sys\n";
qPythonCommand += "sys.path.insert(0, '";
qPythonCommand += qPythonDir.toStdString().c_str();
qPythonCommand += "')\n";
qPythonCommand += "sys.path.insert(0, '/home/simon/Desktop/Code/VirtEnv/lib/python3.12/site-packages/')\n";
qPythonCommand += "print(sys.path)\n";
py::exec(qPythonCommand.toStdString().c_str(), py::globals(), locals);
//
qPythonCommand =
R"PY(
import cppyy
a very simple program - works as it should. but call it a second time (call Test002 again) and it crashes.
"
Hello, World!
['/home/simon/Desktop/Code/VirtEnv/lib/python3.12/site-packages/', '/home/simon/Code/QT/Test_pybind11/Test_pybind11_cppyy_001/', '', '/usr/lib/python312.zip', '/usr/lib/python3.12', '/usr/lib/python3.12/lib-dynload', '/usr/local/lib/python3.12/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.12/dist-packages']
here
there
done
free(): invalid size
*** Break *** abort
#0 0x00007f9cb8710893 in __GI___wait4 (pid=4609, stat_loc=stat_loc
entry=0x7fff23a04f68, options=options
entry=0, usage=usage
entry=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:30 #1 0x00007f9cb87109e7 in __GI___waitpid (pid=, stat_loc=stat_loc
entry=0x7fff23a04f68, options=options
entry=0) at ./posix/waitpid.c:38 #2 0x00007f9cb866891b in do_system (line=) at ../sysdeps/posix/system.c:172 #3 0x00007f9cb5ba1c15 in CppyyLegacy::TUnixSystem::StackTrace() () from /home/simon/Desktop/Code/VirtEnv/lib/python3.12/site-packages/cppyy_backend/lib/libCoreLegacy.so #4 0x00007f9cb5cd94bf in (anonymous namespace)::do_trace (sig=5) at src/clingwrapper.cxx:249 #5 (anonymous namespace)::TExceptionHandlerImp::HandleException (this=, sig=5) at src/clingwrapper.cxx:262
..... #42 0x00007f9cb8ef0ae6 in ?? () from /lib/x86_64-linux-gnu/libpython3.12.so.1.0 #43 0x00007f9cb8ef0bf9 in ?? () from /lib/x86_64-linux-gnu/libpython3.12.so.1.0 #44 0x00007f9cb8ef41bf in PyRun_StringFlags () from /lib/x86_64-linux-gnu/libpython3.12.so.1.0 #45 0x000055ea7e523055 in pybind11::eval<(pybind11::eval_mode)2> (expr=..., global=..., local=...) at /usr/include/pybind11/eval.h:74 #46 0x000055ea7e4fcb2b in pybind11::exec (expr=..., global=..., local=...) at /usr/include/pybind11/eval.h:89 #47 0x000055ea7e4fb462 in Test002 () at /home/simon/Code/QT/Test_pybind11/Test_pybind11_cppyy_001/main.cpp:147 #48 0x000055ea7e4fb1bb in main (argc=1, argv=0x7fff23a09058) at /home/simon/Code/QT/Test_pybind11/Test_pybind11_cppyy_001/main.cpp:32
*** Break *** abort
#0 0x00007f9cb8710893 in __GI___wait4 (pid=4848, stat_loc=stat_loc
entry=0x7fff23a04f68, options=options
entry=0, usage=usage
entry=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:30 #1 0x00007f9cb87109e7 in __GI___waitpid (pid=, stat_loc=stat_loc
entry=0x7fff23a04f68, options=options
entry=0) at ./posix/waitpid.c:38 #2 0x00007f9cb866891b in do_system (line=) at ../sysdeps/posix/system.c:172 #3 0x00007f9cb5ba1c15 in CppyyLegacy::TUnixSystem::StackTrace() () from /home/simon/Desktop/Code/VirtEnv/lib/python3.12/site-packages/cppyy_backend/lib/libCoreLegacy.so #4 0x00007f9cb5cd93cf in (anonymous namespace)::do_trace (sig=5) at src/clingwrapper.cxx:249 #5 (anonymous namespace)::TExceptionHandlerImp::HandleException (this=, sig=5) at src/clingwrapper.cxx:268
.... #41 0x00007f9cb8e97507 in PyEval_EvalCode () from /lib/x86_64-linux-gnu/libpython3.12.so.1.0 #42 0x00007f9cb8ef0ae6 in ?? () from /lib/x86_64-linux-gnu/libpython3.12.so.1.0 #43 0x00007f9cb8ef0bf9 in ?? () from /lib/x86_64-linux-gnu/libpython3.12.so.1.0 #44 0x00007f9cb8ef41bf in PyRun_StringFlags () from /lib/x86_64-linux-gnu/libpython3.12.so.1.0 #45 0x000055ea7e523055 in pybind11::eval<(pybind11::eval_mode)2> (expr=..., global=..., local=...) at /usr/include/pybind11/eval.h:74 #46 0x000055ea7e4fcb2b in pybind11::exec (expr=..., global=..., local=...) at /usr/include/pybind11/eval.h:89 #47 0x000055ea7e4fb462 in Test002 () at /home/simon/Code/QT/Test_pybind11/Test_pybind11_cppyy_001/main.cpp:147 #48 0x000055ea7e4fb1bb in main (argc=1, argv=0x7fff23a09058) at /home/simon/Code/QT/Test_pybind11/Test_pybind11_cppyy_001/main.cpp:32
13:33:11: /home/simon/Code/QT/Test_pybind11/Test_pybind11_cppyy_001/build/Desktop_Qt_6_7_2-Debug/Test_pybind11_cppyy_001 exited with code 133
"
if i run the above cppyy code within a normal python file - it works no matter how many times i run it.
this is that python file:
"
import cppyy
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
hello.
i have embedded python, using pybind11, and then call cppyy with a simple c++ program. it works fine when calling the simple python script once, but call it again and it fails. here is the code (function):
"//
void Test002()
{
//
py::scoped_interpreter guard{};
//
QString qPythonDir("/home/simon/Code/QT/Test_pybind11/Test_pybind11_cppyy_001/");
QString qPythonCommand("");
//
auto locals = py::dict();
auto globals = py::dict();
//
qPythonCommand += "import sys\n";
qPythonCommand += "sys.path.insert(0, '";
qPythonCommand += qPythonDir.toStdString().c_str();
qPythonCommand += "')\n";
qPythonCommand += "sys.path.insert(0, '/home/simon/Desktop/Code/VirtEnv/lib/python3.12/site-packages/')\n";
qPythonCommand += "print(sys.path)\n";
py::exec(qPythonCommand.toStdString().c_str(), py::globals(), locals);
//
qPythonCommand =
R"PY(
import cppyy
cppyy.cppdef("""
#include
void hello()
{
std::cout << "Hello, World!" << std::endl;
}
""")
def runCPP():
global cppyy
print("here")
try:
cppyy.gbl.hello()
print("there")
except Exception as e:
print("Exception: ", e)
print("done")
)PY";
}
"
a very simple program - works as it should. but call it a second time (call Test002 again) and it crashes.
"
Hello, World!
['/home/simon/Desktop/Code/VirtEnv/lib/python3.12/site-packages/', '/home/simon/Code/QT/Test_pybind11/Test_pybind11_cppyy_001/', '', '/usr/lib/python312.zip', '/usr/lib/python3.12', '/usr/lib/python3.12/lib-dynload', '/usr/local/lib/python3.12/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.12/dist-packages']
here
there
done
free(): invalid size
*** Break *** abort
#0 0x00007f9cb8710893 in __GI___wait4 (pid=4609, stat_loc=stat_loc
entry=0x7fff23a04f68, options=options
entry=0, usage=usage
entry=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:30
#1 0x00007f9cb87109e7 in __GI___waitpid (pid=, stat_loc=stat_loc
entry=0x7fff23a04f68, options=options
entry=0) at ./posix/waitpid.c:38
#2 0x00007f9cb866891b in do_system (line=) at ../sysdeps/posix/system.c:172
#3 0x00007f9cb5ba1c15 in CppyyLegacy::TUnixSystem::StackTrace() () from /home/simon/Desktop/Code/VirtEnv/lib/python3.12/site-packages/cppyy_backend/lib/libCoreLegacy.so
#4 0x00007f9cb5cd94bf in (anonymous namespace)::do_trace (sig=5) at src/clingwrapper.cxx:249
#5 (anonymous namespace)::TExceptionHandlerImp::HandleException (this=, sig=5) at src/clingwrapper.cxx:262
.....
#42 0x00007f9cb8ef0ae6 in ?? () from /lib/x86_64-linux-gnu/libpython3.12.so.1.0
#43 0x00007f9cb8ef0bf9 in ?? () from /lib/x86_64-linux-gnu/libpython3.12.so.1.0
#44 0x00007f9cb8ef41bf in PyRun_StringFlags () from /lib/x86_64-linux-gnu/libpython3.12.so.1.0
#45 0x000055ea7e523055 in pybind11::eval<(pybind11::eval_mode)2> (expr=..., global=..., local=...) at /usr/include/pybind11/eval.h:74
#46 0x000055ea7e4fcb2b in pybind11::exec (expr=..., global=..., local=...) at /usr/include/pybind11/eval.h:89
#47 0x000055ea7e4fb462 in Test002 () at /home/simon/Code/QT/Test_pybind11/Test_pybind11_cppyy_001/main.cpp:147
#48 0x000055ea7e4fb1bb in main (argc=1, argv=0x7fff23a09058) at /home/simon/Code/QT/Test_pybind11/Test_pybind11_cppyy_001/main.cpp:32
*** Break *** abort
#0 0x00007f9cb8710893 in __GI___wait4 (pid=4848, stat_loc=stat_loc
entry=0x7fff23a04f68, options=options
entry=0, usage=usage
entry=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:30
#1 0x00007f9cb87109e7 in __GI___waitpid (pid=, stat_loc=stat_loc
entry=0x7fff23a04f68, options=options
entry=0) at ./posix/waitpid.c:38
#2 0x00007f9cb866891b in do_system (line=) at ../sysdeps/posix/system.c:172
#3 0x00007f9cb5ba1c15 in CppyyLegacy::TUnixSystem::StackTrace() () from /home/simon/Desktop/Code/VirtEnv/lib/python3.12/site-packages/cppyy_backend/lib/libCoreLegacy.so
#4 0x00007f9cb5cd93cf in (anonymous namespace)::do_trace (sig=5) at src/clingwrapper.cxx:249
#5 (anonymous namespace)::TExceptionHandlerImp::HandleException (this=, sig=5) at src/clingwrapper.cxx:268
....
#41 0x00007f9cb8e97507 in PyEval_EvalCode () from /lib/x86_64-linux-gnu/libpython3.12.so.1.0
#42 0x00007f9cb8ef0ae6 in ?? () from /lib/x86_64-linux-gnu/libpython3.12.so.1.0
#43 0x00007f9cb8ef0bf9 in ?? () from /lib/x86_64-linux-gnu/libpython3.12.so.1.0
#44 0x00007f9cb8ef41bf in PyRun_StringFlags () from /lib/x86_64-linux-gnu/libpython3.12.so.1.0
#45 0x000055ea7e523055 in pybind11::eval<(pybind11::eval_mode)2> (expr=..., global=..., local=...) at /usr/include/pybind11/eval.h:74
#46 0x000055ea7e4fcb2b in pybind11::exec (expr=..., global=..., local=...) at /usr/include/pybind11/eval.h:89
#47 0x000055ea7e4fb462 in Test002 () at /home/simon/Code/QT/Test_pybind11/Test_pybind11_cppyy_001/main.cpp:147
#48 0x000055ea7e4fb1bb in main (argc=1, argv=0x7fff23a09058) at /home/simon/Code/QT/Test_pybind11/Test_pybind11_cppyy_001/main.cpp:32
13:33:11: /home/simon/Code/QT/Test_pybind11/Test_pybind11_cppyy_001/build/Desktop_Qt_6_7_2-Debug/Test_pybind11_cppyy_001 exited with code 133
"
if i run the above cppyy code within a normal python file - it works no matter how many times i run it.
this is that python file:
"
import cppyy
cppyy.cppdef(r"""
#include
void hello() {
std::cout << "Hello, World!" << std::endl;
}
""")
def runCPP():
print("here")
try:
cppyy.gbl.hello()
print("there")
except Exception as e:
print("Exception: ", e)
print("done")
"
i am stumped as to what it could be. is it an issue with embedding python??
any help or advice please......
Beta Was this translation helpful? Give feedback.
All reactions