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

Guido van Rossum guido at python.org
Mon Mar 8 23:14:51 CET 2010


On Mon, Mar 8, 2010 at 2:01 PM, Victor Stinner <victor.stinner at haypocalc.com> wrote:

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.excinfo())  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.excinfo())  else:  print >>sys.stderr, "'import usercustomize' failed; use -v for traceback" ----------------------

Yes, roughly.

Using these functions, even if sitecustomize fails, usercustomize is imported.

Until 5 minutes ago I didn't even know we had usercustomize. :-)

Can it be a problem? Does usercustomize requires that sitecustomize has been initialized correctly?

I don't know, but if it is, execsitecustomize() could return a flag to be checked by the code that calls execusercustomize().

(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)

Right. It doesn't strike me as a big deal either way.

-- --Guido van Rossum (python.org/~guido)



More information about the Python-Dev mailing list