我用C++编写,我正在创建使用Boost.Python的一个Python包装一个简单的库.有些功能需要很长的时间来执行(超过30秒),我想使它中断,这样,当我按ctrl-d引发一个KeyboardInterrupt在Python解释器,我不知怎么能说++响应的温度.
有没有办法做到这一点?我在boost.org或python.org上找不到有关中断和boost.python的任何信息.
我无法使用以下简单示例来使用SWIG 1.3.40(我也尝试过1.3.31).只要我不将它包装在命名空间中,Foo结构就会作为Python模块出现,但是一旦我这样做,我就会在生成的test_wrap.c中收到编译错误.
test.h:
#ifndef __TEST_H__
#define __TEST_H__
#define USE_NS 1
#if USE_NS
namespace ns {
#endif
struct Foo {
float a;
float b;
float func();
};
#if USE_NS
}
#endif
#endif
Run Code Online (Sandbox Code Playgroud)
TEST.CPP
#include "test.h"
#if USE_NS
namespace ns {
#endif
float Foo::func()
{
return a;
}
#if USE_NS
}
#endif
Run Code Online (Sandbox Code Playgroud)
test.i
%module test
%{
#include "test.h"
%}
%include "test.h"
Run Code Online (Sandbox Code Playgroud)
我在OSX 10.6.3上运行以下命令来构建一个bundle:
swig -python test.i
g++ -c -m64 -fPIC test.cpp
g++ -c -m64 -fPIC -I/usr/local/include -I/opt/local/include -I/opt/local/Library/Frameworks/Python.framework/Headers test_wrap.c
g++ …Run Code Online (Sandbox Code Playgroud)