我在运行c++代码库时遇到python代码退出的问题。我似乎不知道是python代码还是我的c++。任何帮助都将不胜感激
这是我的cpp
class Led {
public:
void snowled()
{
LinuxGPIO gpio23(23);
gpio23.SetDirection(true);
bool on = true;
for (;;)
{
printf("Switching %s the LED...\n", on ? "on" : "off");
gpio23.SetValue(on);
on = !on;
sleep(1);
}
}
};
extern "C" {
Led* Led_new(){ return new Led(); }
void Led_snowled(Led* led){ led->snowled(); }
}
这是我的Python #我尝试调用sys.exit(),但它不会退出
import sys
import time
from ctypes import cdll
lib = cdll.LoadLibrary('./snowled.so')
class Led(object):
def __init__(self):
self.obj = lib.Led_new()
def snowled(self):
lib.Led_snowled(self.obj)
def sleeper(self):
num = float(1)
time.sleep(num)
def main(self):
light = Led()
light.snowled()
def stop_running(self):
try:
sys.exit()
except:
print(sys.exc_info()[0])
if __name__=='__main__':
Led().main()
Led().stop_running()
调用
sys.exit()
实际上引发了SystemExit异常。如果没有参数,退出状态为零你为什么抓住它
相关问题 更多 >
编程相关推荐