C++ code not exiting when wrapped in python
<p>I am having an issue with my python code exiting while running my c++ code lib. I can't seem to figure out if its the python code doing it or my c++. Any help would be greatly appreciated. </p>

<p>Here is my cpp</p>

<pre><code>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-&gt;snowled(); }
}
</code></pre>

<p>here is my python
    #I tried calling sys.exit() but it will not exit. </p>

<pre><code>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()
</code></pre>

<p>The call <code>sys.exit()</code> actually raise a <a href="https://docs.python.org/2/library/exceptions.html#exceptions.SystemExit" rel="nofollow">SystemExit</a> exception. Without parameters, the exit status is zero. </p>

<p>Why do you catch it?</p>

python c++ cpython