我想开发一个测试程序来使用嵌入式python测试C ++应用程序。这是我要修改的示例:https://github.com/skebanga/py_embed。
我想做的是代替test.py中的5硬编码。我想为不同的测试用例传递不同的值。有可能吗?
修改前:上面示例的输出为
./my_program
created script
running
result=10
我的想法是将xmlrpcserver添加到test.py以接受输入。在按如下所示更改test.py并重新生成并运行后,该线程由xmlrpc服务器保留。退出时,将引发如下错误。
有什么建议吗?
./my_program
Listening on port 8000 ...
Hello
127.0.0.1 - - [18/Oct/2018 15:06:34] "POST /RPC2 HTTP/1.1" 200 -
^Cterminate called after throwing an instance of 'boost::python::error_already_set'
Aborted (core dumped)
修改后的test.py
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
from SimpleXMLRPCServer import SimpleXMLRPCServer
class Script(object):
def __init__(self, ifc):
print 'created script'
self.ifc = ifc
def run(self):
print 'running'
self.ifc.execute(5)
self.startRPC()
def result(self, i):
print 'result={}'.format(i)
def startRPC(self):
server = SimpleXMLRPCServer(("", 8000), allow_none=True)
print ("Listening on port 8000 ...")
server.register_instance(self)
server.serve_forever()
我将test.py更改为上面更新的内容。 我还尝试并抓住了main()
int main(){
try{
....
} catch (const bp::error_already_set&)
{
PyErr_Print();
return 1;
}
}
现在输出为:
./my_program
created script
running
result=10
Listening on port 8000 ...
^CTraceback (most recent call last):
File "test.py", line 16, in run
self.startRPC()
File "test.py", line 31, in startRPC
server.serve_forever()
File "/usr/lib/python2.7/SocketServer.py", line 236, in serve_forever
poll_interval)
File "/usr/lib/python2.7/SocketServer.py", line 155, in _eintr_retry
return func(*args)
KeyboardInterrupt
实际上,我注意到不再有核心转储。是因为异常被捕获了吗? 谢谢您的帮助。