Commit 1dc0d91b authored by Neal Norwitz's avatar Neal Norwitz

Remove sys.exc_type, sys.exc_value, sys.exc_traceback

parent 0bc5b7f1
...@@ -233,7 +233,7 @@ def checkop(expr, a, b, value, fuzz = 1e-6): ...@@ -233,7 +233,7 @@ def checkop(expr, a, b, value, fuzz = 1e-6):
try: try:
result = eval(expr) result = eval(expr)
except: except:
result = sys.exc_type result = sys.exc_info()[0]
print '->', result print '->', result
if isinstance(result, str) or isinstance(value, str): if isinstance(result, str) or isinstance(value, str):
ok = (result == value) ok = (result == value)
......
...@@ -83,7 +83,7 @@ class Server: ...@@ -83,7 +83,7 @@ class Server:
method = getattr(self, methodname) method = getattr(self, methodname)
reply = (None, apply(method, args), id) reply = (None, apply(method, args), id)
except: except:
reply = (sys.exc_type, sys.exc_value, id) reply = (sys.exc_info()[:2], id)
if id < 0 and reply[:2] == (None, None): if id < 0 and reply[:2] == (None, None):
if self._verbose > 1: print "Suppress reply" if self._verbose > 1: print "Suppress reply"
return 1 return 1
......
...@@ -191,7 +191,8 @@ def browse_menu(selector, host, port): ...@@ -191,7 +191,8 @@ def browse_menu(selector, host, port):
try: try:
browserfunc(i_selector, i_host, i_port) browserfunc(i_selector, i_host, i_port)
except (IOError, socket.error): except (IOError, socket.error):
print '***', sys.exc_type, ':', sys.exc_value t, v, tb = sys.exc_info()
print '***', t, ':', v
else: else:
print 'Unsupported object type' print 'Unsupported object type'
......
...@@ -23,12 +23,9 @@ carefully propagated, additional calls into the Python/C API may not ...@@ -23,12 +23,9 @@ carefully propagated, additional calls into the Python/C API may not
behave as intended and may fail in mysterious ways. behave as intended and may fail in mysterious ways.
The error indicator consists of three Python objects corresponding to The error indicator consists of three Python objects corresponding to
\withsubitem{(in module sys)}{ the result of \code{sys.exc_info()}. API functions exist to interact
\ttindex{exc_type}\ttindex{exc_value}\ttindex{exc_traceback}} with the error indicator in various ways. There is a separate
the Python variables \code{sys.exc_type}, \code{sys.exc_value} and error indicator for each thread.
\code{sys.exc_traceback}. API functions exist to interact with the
error indicator in various ways. There is a separate error indicator
for each thread.
% XXX Order of these should be more thoughtful. % XXX Order of these should be more thoughtful.
% Either alphabetical or some kind of structure. % Either alphabetical or some kind of structure.
......
...@@ -400,15 +400,12 @@ exception state. ...@@ -400,15 +400,12 @@ exception state.
The full exception state consists of three objects (all of which can The full exception state consists of three objects (all of which can
be \NULL): the exception type, the corresponding exception be \NULL): the exception type, the corresponding exception
value, and the traceback. These have the same meanings as the Python value, and the traceback. These have the same meanings as the Python
\withsubitem{(in module sys)}{ result of \code{sys.exc_info()}; however, they are not the same: the Python
\ttindex{exc_type}\ttindex{exc_value}\ttindex{exc_traceback}}
objects \code{sys.exc_type}, \code{sys.exc_value}, and
\code{sys.exc_traceback}; however, they are not the same: the Python
objects represent the last exception being handled by a Python objects represent the last exception being handled by a Python
\keyword{try} \ldots\ \keyword{except} statement, while the C level \keyword{try} \ldots\ \keyword{except} statement, while the C level
exception state only exists while an exception is being passed on exception state only exists while an exception is being passed on
between C functions until it reaches the Python bytecode interpreter's between C functions until it reaches the Python bytecode interpreter's
main loop, which takes care of transferring it to \code{sys.exc_type} main loop, which takes care of transferring it to \code{sys.exc_info()}
and friends. and friends.
Note that starting with Python 1.5, the preferred, thread-safe way to Note that starting with Python 1.5, the preferred, thread-safe way to
......
...@@ -120,9 +120,8 @@ variable is \NULL{} no exception has occurred. A second global ...@@ -120,9 +120,8 @@ variable is \NULL{} no exception has occurred. A second global
variable stores the ``associated value'' of the exception (the second variable stores the ``associated value'' of the exception (the second
argument to \keyword{raise}). A third variable contains the stack argument to \keyword{raise}). A third variable contains the stack
traceback in case the error originated in Python code. These three traceback in case the error originated in Python code. These three
variables are the C equivalents of the Python variables variables are the C equivalents of the result in Python of
\code{sys.exc_type}, \code{sys.exc_value} and \code{sys.exc_traceback} (see \method{sys.exc_info()} (see the section on module \module{sys} in the
the section on module \module{sys} in the
\citetitle[../lib/lib.html]{Python Library Reference}). It is \citetitle[../lib/lib.html]{Python Library Reference}). It is
important to know about them to understand how errors are passed important to know about them to understand how errors are passed
around. around.
......
...@@ -12,9 +12,8 @@ when you want to print stack traces under program control, such as in a ...@@ -12,9 +12,8 @@ when you want to print stack traces under program control, such as in a
``wrapper'' around the interpreter. ``wrapper'' around the interpreter.
The module uses traceback objects --- this is the object type that is The module uses traceback objects --- this is the object type that is
stored in the variables \code{sys.exc_traceback} (deprecated) and stored in the \code{sys.last_traceback} variable and returned
\code{sys.last_traceback} and returned as the third item from as the third item from \function{sys.exc_info()}.
\function{sys.exc_info()}.
\obindex{traceback} \obindex{traceback}
The module defines the following functions: The module defines the following functions:
...@@ -41,11 +40,7 @@ with a caret indicating the approximate position of the error. ...@@ -41,11 +40,7 @@ with a caret indicating the approximate position of the error.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{print_exc}{\optional{limit\optional{, file}}} \begin{funcdesc}{print_exc}{\optional{limit\optional{, file}}}
This is a shorthand for \code{print_exception(sys.exc_type, This is a shorthand for \code{print_exception(*\function{sys.exc_info()}}.
sys.exc_value, sys.exc_traceback, \var{limit}, \var{file})}. (In
fact, it uses \function{sys.exc_info()} to retrieve the same
information in a thread-safe way instead of using the deprecated
variables.)
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{format_exc}{\optional{limit}} \begin{funcdesc}{format_exc}{\optional{limit}}
......
...@@ -250,21 +250,15 @@ occurs in the try clause of the inner handler, the outer handler will ...@@ -250,21 +250,15 @@ occurs in the try clause of the inner handler, the outer handler will
not handle the exception.) not handle the exception.)
Before an except clause's suite is executed, details about the Before an except clause's suite is executed, details about the
exception are assigned to three variables in the exception are stored in the \module{sys}\refbimodindex{sys} module
\module{sys}\refbimodindex{sys} module: \code{sys.exc_type} receives and can be access via \function{sys.exc_info()}. \function{sys.exc_info()}
the object identifying the exception; \code{sys.exc_value} receives returns a 3-tuple consisting of: \code{exc_type} receives
the exception's parameter; \code{sys.exc_traceback} receives a the object identifying the exception; \code{exc_value} receives
the exception's parameter; \code{exc_traceback} receives a
traceback object\obindex{traceback} (see section~\ref{traceback}) traceback object\obindex{traceback} (see section~\ref{traceback})
identifying the point in the program where the exception occurred. identifying the point in the program where the exception occurred.
These details are also available through the \function{sys.exc_info()} \function{sys.exc_info()} values are restored to their previous values
function, which returns a tuple \code{(\var{exc_type}, \var{exc_value}, (before the call) when returning from a function that handled an exception.
\var{exc_traceback})}. Use of the corresponding variables is
deprecated in favor of this function, since their use is unsafe in a
threaded program. As of Python 1.5, the variables are restored to
their previous values (before the call) when returning from a function
that handled an exception.
\withsubitem{(in module sys)}{\ttindex{exc_type}
\ttindex{exc_value}\ttindex{exc_traceback}}
The optional \keyword{else} clause is executed if and when control The optional \keyword{else} clause is executed if and when control
flows off the end of the \keyword{try} clause.\footnote{ flows off the end of the \keyword{try} clause.\footnote{
......
...@@ -261,7 +261,7 @@ class SimpleXMLRPCDispatcher: ...@@ -261,7 +261,7 @@ class SimpleXMLRPCDispatcher:
except: except:
# report exception back to server # report exception back to server
response = xmlrpclib.dumps( response = xmlrpclib.dumps(
xmlrpclib.Fault(1, "%s:%s" % (sys.exc_type, sys.exc_value)), xmlrpclib.Fault(1, "%s:%s" % sys.exc_info()[:2]),
encoding=self.encoding, allow_none=self.allow_none, encoding=self.encoding, allow_none=self.allow_none,
) )
...@@ -362,7 +362,7 @@ class SimpleXMLRPCDispatcher: ...@@ -362,7 +362,7 @@ class SimpleXMLRPCDispatcher:
except: except:
results.append( results.append(
{'faultCode' : 1, {'faultCode' : 1,
'faultString' : "%s:%s" % (sys.exc_type, sys.exc_value)} 'faultString' : "%s:%s" % sys.exc_info()[:2]}
) )
return results return results
......
...@@ -45,8 +45,8 @@ class WindowList: ...@@ -45,8 +45,8 @@ class WindowList:
try: try:
callback() callback()
except: except:
print "warning: callback failed in WindowList", \ t, v, tb = sys.exc_info()
sys.exc_type, ":", sys.exc_value print "warning: callback failed in WindowList", t, ":", v
registry = WindowList() registry = WindowList()
......
...@@ -1108,7 +1108,7 @@ class Misc: ...@@ -1108,7 +1108,7 @@ class Misc:
def _report_exception(self): def _report_exception(self):
"""Internal function.""" """Internal function."""
import sys import sys
exc, val, tb = sys.exc_type, sys.exc_value, sys.exc_traceback exc, val, tb = sys.exc_info()
root = self._root() root = self._root()
root.report_callback_exception(exc, val, tb) root.report_callback_exception(exc, val, tb)
def _configure(self, cmd, cnf, kw): def _configure(self, cmd, cnf, kw):
......
...@@ -203,9 +203,7 @@ def _some_str(value): ...@@ -203,9 +203,7 @@ def _some_str(value):
def print_exc(limit=None, file=None): def print_exc(limit=None, file=None):
"""Shorthand for 'print_exception(sys.exc_type, sys.exc_value, sys.exc_traceback, limit, file)'. """Shorthand for 'print_exception(*sys.exc_info(), limit, file)'."""
(In fact, it uses sys.exc_info() to retrieve the same information
in a thread-safe way.)"""
if file is None: if file is None:
file = sys.stderr file = sys.stderr
try: try:
......
...@@ -105,7 +105,8 @@ class Debugger(bdb.Bdb): ...@@ -105,7 +105,8 @@ class Debugger(bdb.Bdb):
raise 'spam' raise 'spam'
except: except:
pass pass
frame = sys.exc_traceback.tb_frame tb = sys.exc_info()[2]
frame = tb.tb_frame
while frame is not None: while frame is not None:
del frame.f_trace del frame.f_trace
frame = frame.f_back frame = frame.f_back
...@@ -527,7 +528,7 @@ class Debugger(bdb.Bdb): ...@@ -527,7 +528,7 @@ class Debugger(bdb.Bdb):
raise bdb.BdbQuit raise bdb.BdbQuit
except: except:
print 'XXX Exception during debugger interaction.', \ print 'XXX Exception during debugger interaction.', \
self.formatexception(sys.exc_type, sys.exc_value) self.formatexception(sys.exc_info[:2])
import traceback import traceback
traceback.print_exc() traceback.print_exc()
return self.trace_dispatch return self.trace_dispatch
...@@ -855,7 +856,8 @@ def startfromhere(): ...@@ -855,7 +856,8 @@ def startfromhere():
try: try:
raise 'spam' raise 'spam'
except: except:
frame = sys.exc_traceback.tb_frame.f_back tb = sys.exc_info()[2]
frame = tb.tb_frame.f_back
d.start(frame) d.start(frame)
def startfrombottom(): def startfrombottom():
...@@ -876,7 +878,8 @@ def _getbottomframe(): ...@@ -876,7 +878,8 @@ def _getbottomframe():
raise 'spam' raise 'spam'
except: except:
pass pass
frame = sys.exc_traceback.tb_frame tb = sys.exc_info()[2]
frame = tb.tb_frame
while 1: while 1:
if frame.f_code.co_name == 'mainloop' or frame.f_back is None: if frame.f_code.co_name == 'mainloop' or frame.f_back is None:
break break
......
...@@ -1212,7 +1212,7 @@ def execstring(pytext, globals, locals, filename="<string>", debugging=0, ...@@ -1212,7 +1212,7 @@ def execstring(pytext, globals, locals, filename="<string>", debugging=0,
except: except:
if debugging: if debugging:
sys.settrace(None) sys.settrace(None)
PyDebugger.postmortem(sys.exc_type, sys.exc_value, sys.exc_traceback) PyDebugger.postmortem(*sys.exc_info())
return return
else: else:
tracebackwindow.traceback(1, filename) tracebackwindow.traceback(1, filename)
...@@ -1289,7 +1289,6 @@ class _EditorDefaultSettings: ...@@ -1289,7 +1289,6 @@ class _EditorDefaultSettings:
settings = FontSettings.FontDialog(self.fontsettings, self.tabsettings) settings = FontSettings.FontDialog(self.fontsettings, self.tabsettings)
if settings: if settings:
self.fontsettings, self.tabsettings = settings self.fontsettings, self.tabsettings = settings
sys.exc_traceback = None
self.w.fonttext.set(self.template % (self.fontsettings[0], self.fontsettings[2])) self.w.fonttext.set(self.template % (self.fontsettings[0], self.fontsettings[2]))
def close(self): def close(self):
...@@ -1327,7 +1326,6 @@ def geteditorprefs(): ...@@ -1327,7 +1326,6 @@ def geteditorprefs():
fontsettings = prefs.pyedit.fontsettings = ("Geneva", 0, 10, (0, 0, 0)) fontsettings = prefs.pyedit.fontsettings = ("Geneva", 0, 10, (0, 0, 0))
tabsettings = prefs.pyedit.tabsettings = (8, 1) tabsettings = prefs.pyedit.tabsettings = (8, 1)
windowsize = prefs.pyedit.windowsize = (500, 250) windowsize = prefs.pyedit.windowsize = (500, 250)
sys.exc_traceback = None
return fontsettings, tabsettings, windowsize return fontsettings, tabsettings, windowsize
def seteditorprefs(fontsettings, tabsettings, windowsize): def seteditorprefs(fontsettings, tabsettings, windowsize):
......
...@@ -179,10 +179,6 @@ sys_exc_clear(PyObject *self, PyObject *noargs) ...@@ -179,10 +179,6 @@ sys_exc_clear(PyObject *self, PyObject *noargs)
Py_XDECREF(tmp_type); Py_XDECREF(tmp_type);
Py_XDECREF(tmp_value); Py_XDECREF(tmp_value);
Py_XDECREF(tmp_tb); Py_XDECREF(tmp_tb);
/* For b/w compatibility */
PySys_SetObject("exc_type", Py_None);
PySys_SetObject("exc_value", Py_None);
PySys_SetObject("exc_traceback", Py_None);
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
......
...@@ -27,7 +27,7 @@ try: ...@@ -27,7 +27,7 @@ try:
except SystemExit, n: except SystemExit, n:
sys.exit(n) sys.exit(n)
except: except:
t, v, tb = sys.exc_type, sys.exc_value, sys.exc_traceback t, v, tb = sys.exc_info()
print print
import cgi import cgi
cgi.print_exception(t, v, tb) cgi.print_exception(t, v, tb)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment