title: KeyError stopping App in kivy
body: <p>I'm trying to get an application I've been building to stop at a certain point, and run a cleanup procedure on stop. This seems like it should be easy, but I keep encountering an error, and I haven't been able to track down a solution.</p>
  
  <p>I use kivy 1.8.0 and Python 3.3. For ease, I've modified some code from the kivy documentation, since my code is based on the same framework, and both give me exactly the same error:</p>
  
  <pre><code>from kivy.app import App
  from kivy.lang import Builder
  from kivy.uix.screenmanager import ScreenManager, Screen    
  # Create both screens. Please note the root.manager.current: this is how
  # you can control the ScreenManager from kv. Each screen has by default a
  # property manager that gives you the instance of the ScreenManager used.
  Builder.load_string("""
  &lt;MenuScreen&gt;:
      BoxLayout:
          Button:
              text: 'Goto settings'
              on_press: root.manager.current = 'settings'
          Button:
              text: 'Quit'
              on_press: root.exit()
  
  &lt;SettingsScreen&gt;:
      BoxLayout:
          Button:
              text: 'My settings button'
          Button:
              text: 'Back to menu'
              on_press: root.manager.current = 'menu'    
  """)
  
  # Declare both screens
  class MenuScreen(Screen):
      def exit(self):
          App.stop(self)
  
  
  class SettingsScreen(Screen):
      pass     
  
  # Create the screen manager
  sm = ScreenManager()
  sm.add_widget(MenuScreen(name='menu'))
  sm.add_widget(SettingsScreen(name='settings'))
  
  class TestApp(App):
  
      def build(self):
          return sm
  
      def on_stop(self):
          print('leaving now') # this is where I'd want to run the end of program procedure
  
  if __name__ == '__main__':
      TestApp().run()
  </code></pre>
  
  <p>When I run this and click on the <code>Quit</code> button, I get the following error:</p>
  
  <pre><code>builtins.KeyError: 'on_stop'
  </code></pre>
  
  <p>I should also note that if I comment out the <code>on_stop</code> function in <code>class TestApp</code>, the error persists. Any idea what is going wrong?</p>