On Tue, 2005-08-02 at 15:03 +0200, Dirk Meyer wrote:
> Question here: do you need to call shutdown? I wanted to change the
> code to hide shutdown. When you want to leave kaa.main(), use
> sys.exit(0) to leave the loop and shutdown the system. IMHO it is a
> cleaner way. 

Because calling sys.exit() does undesirable things if it's done in one
of the shutdown signal callbacks, because at that point it's out of the
notifier loop, it will exit immediately, rather than finish the rest of
the shutdown callbacks.

I want a function I can call to quit that will Do the Right Thing in any
circumstance.

A practical example: kaa.mplayer.MPlayer has a "quit" signal that is
emitted when MPlayer exits.  In test/mplayer.py, it has:

    mp.signals["quit"].connect(kaa.shutdown)

But in order to shut MPlayer down gracefully when kaa exits, kaa.mplayer
also has this:

    kaa.signals["shutdown"].connect(self.quit)

When self.quit() executes, the "quit" signal emits in MPlayer.  So what
happens is that if I had attached sys.exit to the quit signal, if the
main loop exits while MPlayer is still running, it emits a shutdown
signal, MPlayer.quit() gets called, emits a quit signal, and sys.exit
gets called, and because it's outside the notifier loop at this point,
the whole application quits immediately.

Instead kaa.shutdown() will do the right thing regardless of the
circumstance.  It will exit the notifier loop if running, or be ignored
it's already shut down.  In contrast, sys.exit only does the right thing
when the notifier loop is running.

Cheers,
Jason.

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to