[英]can't kill process by Ctrl-c in a boost.python module with an endless loop
I have make a boost.python module with an endless loop.But I can't kill the process by ctrl-c.The following is an example. 我用一个无限循环制作了一个boost.python模块。但我不能通过ctrl-c杀死进程。以下是一个例子。
C++ C ++
#include <boost/python.hpp>
#include <boost/python.module.hpp>
#include <boost/python.def.hpp>
#include <iostream>
usring namespace boost::python;
void foo() {
int it=0;
while (true) { //endless loop
++it;
std::cout<< it <<std::endl;
sleep(3);
}
}
BOOST_PYTHON_MODULE(ctopy)
{
def("foo",foo);
}
python: 蟒蛇:
import ctopy
ctopy.foo()
result: 结果:
1
2
3
4
.....................
I can't kill the foreground process by Ctrl-c.why the module don't accept signal "SIGINT" that was sent by Ctrl-c.How to make it work. 我无法通过Ctrl-c终止前台进程。为什么模块不接受Ctrl-c发送的信号“SIGINT”。如何使其工作。
you should call PyErr_CheckSignals() periodically in your extension code and call exit()
if it returns -1
: 你应该在你的扩展代码中定期调用PyErr_CheckSignals()并调用
exit()
如果它返回-1
:
while (true) { //endless loop
++it;
std::cout<< it <<std::endl;
sleep(3);
if(PyErr_CheckSignals() == -1) {
exit(1);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.