Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Multiple calls to Python interpreter embedded in C++ application yield segmentation f
Dear Forum,

I have asked this question before at stackoverflow but did not get any answer.

Please consider the following mini application that creates a string containing QASM code in the host application and invokes the Python interpreter:

#include <Python.h>
#include <sstream>

static void run()
  std::stringstream ss;

  ss << "import pyquil\n";


int main()
  return 0;
Obviously, this code does not do anything useful but it yields a segmentation fault in the second call to the run() function when the pyquil module is imported. I have been using the same approach (multiple calls to embedded Python interpreter) with other Python modules and it works without problems.

The developers of pyquil consider this a Python problem and/or wrong usage of the embedded Python interpreter. Running the program through gdb yields
Program received signal SIGSEGV, Segmentation fault. 0x00007fffef7369e8 in PyArray_Item_INCREF (data=data@entry=0x7fffd9319ec0 "\n", descr=descr@entry=0x7fffefb692a0 <OBJECT_Descr>) at numpy/core/src/multiarray/refcount.c:39 39 numpy/core/src/multiarray/refcount.c: No such file or directory. Missing separate debuginfos, use: debuginfo-install libuuid-2.23.2-59.el7_6.1.x86_64 openssl-libs-1.0.2k-16.el7_6.1.x86_64 (gdb) where #0 0x00007fffef7369e8 in PyArray_Item_INCREF (data=data@entry=0x7fffd9319ec0 "\n", descr=descr@entry=0x7fffefb692a0 <OBJECT_Descr>) at numpy/core/src/multiarray/refcount.c:39 #1 0x00007fffef739f5b in PyArray_FromScalar (scalar=<optimized out>, outcode=outcode@entry=0x0) at numpy/core/src/multiarray/scalarapi.c:335 #2 0x00007fffef73b98c in gentype_nonzero_number (m1=<optimized out>) at numpy/core/src/multiarray/scalartypes.c.src:350 #3 0x00007ffff79abfc7 in PyObject_IsTrue (v=v@entry=0x7fffd9319eb0) at /usr/src/debug/Python-3.6.7/Objects/object.c:1243 #4 0x00007ffff7a1f981 in _PyEval_EvalFrameDefault (f=<optimized out>, throwflag=<optimized out>) at /usr/src/debug/Python-3.6.7/Python/ceval.c:2960 #5 0x00007ffff7a1d5e0 in _PyFunction_FastCall (co=<optimized out>, args=<optimized out>, nargs=2, globals=<optimized out>) at /usr/src/debug/Python-3.6.7/Python/ceval.c:4919 #6 0x00007ffff7a1e18e in fast_function (func=<optimized out>, stack=<optimized out>, nargs=<optimized out>, kwnames=<optimized out>) at /usr/src/debug/Python-3.6.7/Python/ceval.c:4961 #7 0x00007ffff7a1e2f6 in call_function (pp_stack=pp_stack@entry=0x7fffffff46f0, oparg=<optimized out>, kwnames=kwnames@entry=0x0) at /usr/src/debug/Python-3.6.7/Python/ceval.c:4858 #8 0x00007ffff7a224c4 in _PyEval_EvalFrameDefault (f=<optimized out>, throwflag=<optimized out>) at /usr/src/debug/Python-3.6.7/Python/ceval.c:3335 #9 0x00007ffff7a1d5e0 in _PyFunction_FastCall (co=co@entry=0x7fffda5a49c0, args=<optimized out>, args@entry=0x7fffffff4910, nargs=nargs@entry=2, globals=globals@entry=0x7fffd5c86ea0) at /usr/src/debug/Python-3.6.7/Python/ceval.c:4919 #10 0x00007ffff7a27576 in _PyFunction_FastCallDict (func=func@entry=0x7ffff7eedbf8, args=args@entry=0x7fffffff4910, nargs=2, kwargs=kwargs@entry=0x0) at /usr/src/debug/Python-3.6.7/Python/ceval.c:5021
Any help how to further debug this problem and decide whether its a problem with pyquil or my wrong usage of the embedded Python interpreter is highly appreciated. Thank you very much!

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Installing Python Application pplgf 3 177 Apr-27-2020, 10:51 PM
Last Post: Larz60+
  Python interpreter - output to file SectionProperties 8 370 Apr-11-2020, 01:38 PM
Last Post: SectionProperties
  Problem about yield, please help!! cls0724 5 248 Apr-08-2020, 05:37 PM
Last Post: deanhystad
  does yield support variable args? Skaperen 0 154 Mar-03-2020, 02:44 AM
Last Post: Skaperen
  Embedded Python PyObject_CallObject function JRHeisey 1 274 Nov-27-2019, 01:50 AM
Last Post: casevh
  Segmentation fault with large files kusal1 3 313 Oct-01-2019, 07:32 AM
Last Post: Gribouillis
  Need help with a function that calls other functions. skurrtboi 4 276 Sep-30-2019, 09:28 PM
Last Post: stullis
  OpenCV - Segmentation fault samtwilliams 6 1,492 Sep-18-2019, 12:01 AM
Last Post: Larz60+
  How to intercept python method calls? DineshBhat 0 329 Jul-15-2019, 03:46 AM
Last Post: DineshBhat
  Where is usually located the python interpreter on android devices? anddontyoucomebacknomore 1 472 Jul-03-2019, 06:32 PM
Last Post: metulburr

Forum Jump:

Users browsing this thread: 1 Guest(s)