Add traceback.format_exc().
diff --git a/Lib/threading.py b/Lib/threading.py
index 81a2693..c5d5af3 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -8,9 +8,8 @@
del _sys.modules[__name__]
raise
-from StringIO import StringIO as _StringIO
from time import time as _time, sleep as _sleep
-from traceback import print_exc as _print_exc
+from traceback import format_exc as _format_exc
# Rename some stuff so "from threading import *" is safe
__all__ = ['activeCount', 'Condition', 'currentThread', 'enumerate', 'Event',
@@ -440,10 +439,8 @@
except:
if __debug__:
self._note("%s.__bootstrap(): unhandled exception", self)
- s = _StringIO()
- _print_exc(file=s)
_sys.stderr.write("Exception in thread %s:\n%s\n" %
- (self.getName(), s.getvalue()))
+ (self.getName(), _format_exc()))
else:
if __debug__:
self._note("%s.__bootstrap(): normal return", self)
diff --git a/Lib/traceback.py b/Lib/traceback.py
index 4910a37..d99009b 100644
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -6,8 +6,8 @@
__all__ = ['extract_stack', 'extract_tb', 'format_exception',
'format_exception_only', 'format_list', 'format_stack',
- 'format_tb', 'print_exc', 'print_exception', 'print_last',
- 'print_stack', 'print_tb', 'tb_lineno']
+ 'format_tb', 'print_exc', 'format_exc', 'print_exception',
+ 'print_last', 'print_stack', 'print_tb', 'tb_lineno']
def _print(file, str='', terminator='\n'):
file.write(str+terminator)
@@ -211,6 +211,16 @@
finally:
etype = value = tb = None
+
+def format_exc(limit=None):
+ """Like print_exc() but return a string."""
+ try:
+ etype, value, tb = sys.exc_info()
+ return ''.join(format_exception(etype, value, tb, limit))
+ finally:
+ etype = value = tb = None
+
+
def print_last(limit=None, file=None):
"""This is a shorthand for 'print_exception(sys.last_type,
sys.last_value, sys.last_traceback, limit, file)'."""