也不确定哪里出了问题。
根据目前了解的情况,出错原因如下:
新产生一个数组缓冲区。
产生调用Python的数组参数。
销毁该缓冲区。
调用Python函数。
这时发现这个缓冲区已经销毁了,于是出错了。
正确做法是,3、4颠倒。
参考《C向Python传递数组参数时,调用函数后才能销毁》。
#0 0x00007f474329b984 in ?? () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 [Current thread is 1 (Thread 0x7f470affd700 (LWP 31868))] (gdb) (gdb) backtrace #0 0x00007f474329b984 in ?? () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #1 0x00007f4743324106 in ?? () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #2 0x00007f47432a01a7 in ?? () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #3 0x00007f47432a0e3b in _PyObject_GC_Malloc () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #4 0x00007f47432903eb in PyType_GenericAlloc () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #5 0x00007f4608204ab8 in THPVariable_NewWithVar (type=<optimized out>, var=...) at torch/csrc/autograd/python_variable.cpp:48 #6 0x00007f4608206659 in THPVariable_Wrap (var=...) at torch/csrc/autograd/python_variable.cpp:75 #7 0x00007f460820dcbc in torch::autograd::utils::wrap (tensor=...) at /pytorch/torch/csrc/autograd/utils/wrap_outputs.h:18 #8 torch::autograd::THPVariable_getitem (self=0x7f45b015f370, index=0x7f4690018a58) at torch/csrc/autograd/python_variable_indexing.cpp:292 #9 0x00007f47432739fd in PyEval_EvalFrameEx () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #10 0x00007f47433af11c in PyEval_EvalCodeEx () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 ---Type <return> to continue, or q <return> to quit--- #11 0x00007f47433053b0 in ?? () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #12 0x00007f47432d82b3 in PyObject_Call () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #13 0x00007f474324474a in ?? () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #14 0x00007f47432d7afb in PyIter_Next () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #15 0x00007f474327b593 in ?? () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #16 0x00007f47432799b1 in PyEval_EvalFrameEx () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #17 0x00007f47433af11c in PyEval_EvalCodeEx () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #18 0x00007f4743277f5d in PyEval_EvalFrameEx () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #19 0x00007f47433af11c in PyEval_EvalCodeEx () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #20 0x00007f47433053b0 in ?? () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #21 0x00007f47432d82b3 in PyObject_Call () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #22 0x00007f474334c46c in ?? () ---Type <return> to continue, or q <return> to quit--- from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #23 0x00007f47432d82b3 in PyObject_Call () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #24 0x00007f47432f9535 in ?? () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #25 0x00007f47432d82b3 in PyObject_Call () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #26 0x00007f474327639c in PyEval_EvalFrameEx () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #27 0x00007f47433af11c in PyEval_EvalCodeEx () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #28 0x00007f47433053b0 in ?? () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #29 0x00007f47432d82b3 in PyObject_Call () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #30 0x00007f474334c46c in ?? () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #31 0x00007f47432d82b3 in PyObject_Call () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #32 0x00007f47432f9535 in ?? () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #33 0x00007f47432d82b3 in PyObject_Call () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 ---Type <return> to continue, or q <return> to quit--- #34 0x00007f474327639c in PyEval_EvalFrameEx () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #35 0x00007f47433af11c in PyEval_EvalCodeEx () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #36 0x00007f4743277f5d in PyEval_EvalFrameEx () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #37 0x00007f47433af11c in PyEval_EvalCodeEx () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #38 0x00007f47433053b0 in ?? () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #39 0x00007f47432d82b3 in PyObject_Call () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #40 0x00007f474334c46c in ?? () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #41 0x00007f47432d82b3 in PyObject_Call () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #42 0x00007f47432f9535 in ?? () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #43 0x00007f47432d82b3 in PyObject_Call () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #44 0x00007f474327639c in PyEval_EvalFrameEx () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #45 0x00007f47433af11c in PyEval_EvalCodeEx () ---Type <return> to continue, or q <return> to quit--- from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #46 0x00007f47433053b0 in ?? () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #47 0x00007f47432d82b3 in PyObject_Call () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #48 0x00007f47433ae547 in PyEval_CallObjectWithKeywords () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 #49 0x00007f4746ae7342 in PythonClass::python_function (this=0x7f46900008c0,