[Python-Dev] Catch SIGINT at Python startup (original) (raw)

Victor Stinner victor.stinner at haypocalc.com
Mon Mar 8 23:01:34 CET 2010


Le lundi 08 mars 2010 22:06:36, vous avez écrit :

OTOH I think the try/except in site.py around the execution of sitecustomize.py might be changed so that it prints a full traceback whenever it raises an exception other than ImportError or, again, exceptions inheriting from BaseException but not from Exception. IOW I think that exceptions coming out of sitecustomize.py should continued to be treated non-fatally, apart from ^C and friends, but I think that exceptions coming out of site.py might be considered more fatally once the change to exceptions coming out of sitecustomize.py is made.

Do you mean something like the following code?

def execsitecustomize(): """Run custom site specific code, if available.""" try: import sitecustomize except ImportError: pass except Exception: if sys.flags.verbose: sys.excepthook(*sys.exc_info()) else: print >>sys.stderr, "'import sitecustomize' failed; use -v for traceback"

def execusercustomize(): """Run custom user specific code, if available.""" try: import usercustomize except ImportError: pass except Exception: if sys.flags.verbose: sys.excepthook(*sys.exc_info()) else: print >>sys.stderr, "'import usercustomize' failed; use -v for traceback"

Using these functions, even if sitecustomize fails, usercustomize is imported. Can it be a problem? Does usercustomize requires that sitecustomize has been initialized correctly?

(The code can be changed to only import usercustomize if sitecutomize succeed or failed with an ImportError, but not if it fails with a different error)

-- Victor Stinner http://www.haypocalc.com/



More information about the Python-Dev mailing list