Python 2.4 vs. 2.5 - sys.exit() throwing an Exception.

| 3 Comments | No TrackBacks

Some couple of days ago I came across a rather annoying problem - I had a simple Python program that worked perfectly on my computer, while deployed on the target machine - it failed. What turned to be the problem?

Well, the thing is that I don't read change logs :) If I did, I wouldn't have wasted about a half an hour looking for my mistake.

OK, so for those of you that are still reading this, here goes the detailed version.

And now the results:

So, 2.5 behaves as I expected it to be, while 2.4 seemed to get it quite strange... why, oh why? Here's why:

Python Module Exceptions

Solution - RTFM! :)

No TrackBacks

TrackBack URL: http://mt.onoclea.com/mt-tb.cgi/3

3 Comments

Being too lazy to dig any spec I just say: I don't get it.
According to the documentation (http://docs.python.org/lib/module-sys.html 'exit' function) this is 2.5 to blame for unexpected behaviour. Python 2.4 seems to follow the docs by throwing a SystemExit exception.

I think it does make sense (quote from the docs):

"The exception inherits from BaseException instead of StandardError or Exception so that it is not accidentally caught by code that catches Exception. This allows the exception to properly propagate up and cause the interpreter to exit. Changed in version 2.5: Changed to inherit from BaseException."

So in 2.5 they changed the SystemExit to inherit from BaseException and not Exception.

In the example above SystemExit was caught in 2.4 since it inherits from the Exception, while in 2.5 it is BaseException instead.

Silly me. That's a "RTFM with understanding" for sure:)

Leave a comment

About this Entry

This page contains a single entry by Paweł J. Sawicki published on May 18, 2008 6:32 PM.

Postfix + Dovecot LDA - Impossible is nothing! was the previous entry in this blog.

Maintenance free machines... is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.