title: Python - How do I keep a Gtk.Application running when there are no windows?
body: <p>I want to keep the application running in the background even when all it's windows are closed. Is there a function or something to do this? I couldn't find an answer on SO. Here is my code:</p>
  <pre><code>import gi
  import sys
  
  gi.require_version(&quot;Gtk&quot;, &quot;3.0&quot;)
  from gi.repository import Gtk
  
  class App(Gtk.Application):
      &quot;&quot;&quot;The application manager.&quot;&quot;&quot;
  
      def __init__(self, *args, **kwargs):
          Gtk.Application.__init__(
              self,
              *args,
              application_id=&quot;org.app_test&quot;,
              # flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE,
              **kwargs
          )
  
          # We are only allowed to have one window
          self.window = None
  
      def do_activate(self):
          &quot;&quot;&quot;Activate the app.&quot;&quot;&quot;
  
          # Create the window, if it does not exist
          if self.window is None:
              self.window = AppWindow(application=self, title=&quot;MusicApp&quot;, name=&quot;0&quot;)
              self.window.present()
  
      def do_startup(self):
          &quot;&quot;&quot;Start the app.&quot;&quot;&quot;
          Gtk.Application.do_startup(self)
  
  class AppWindow(Gtk.ApplicationWindow):
      &quot;&quot;&quot;The main window for the application.&quot;&quot;&quot;
  
      def __init__(self, *args, application, **kwargs):
          Gtk.ApplicationWindow.__init__(
              self,
              *args,
              application=application,
              **kwargs
          )
  
          # The application
          self.app = application
  
          self.show_all()
  
  if __name__ == &quot;__main__&quot;:
      app = App()
      app.run(sys.argv)
  </code></pre>
  <p>When I close the window, the program stops. How do I make it continue running even if all the windows are closed?</p>