Coding Style: exiting python programs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hey all - here is a quick note about the various ways to exit python
programs. Consider this a suggestion for a future CodingStyle / New
Developer FAQ, or something.


sys.exit(returncode) really just does:
    raise SystemExit(returncode)
So we can use that rather than importing sys just for sys.exit().

Note that SystemExit is a subclass of Exception, so if you're handling
Exception anywhere, you're going to catch SystemExit/sys.exit().
(This is another reason 'except Exception: ..." is a bad idea.)

As pointed out elsewhere, if a thread catches SystemExit the thread will
exit, but not the entire program.

If you really want to exit immediately without dealing with exception
handling or cleanup or threading, there's os._exit(). This should cause
a threaded python program to exit even if called from a thread.


Hope that helps someone,

-w

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux