Код C ++ не завершается при переносе в python

У меня проблема с выходом из моего кода Python при запуске моей библиотеки кода на C ++. Кажется, я не могу понять, делает ли это код на 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(); }
}

вот мой питон
# Я пытался вызвать 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()

-1

Решение

Вызов sys.exit() на самом деле поднять SystemExit исключение. Без параметров статус выхода равен нулю.

Почему вы ловите это?

0

Другие решения

Других решений пока нет …