Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3.3
Changeset: r73045:e7c8a2c8d8e8
Date: 2014-08-02 22:03 +0200
http://bitbucket.org/pypy/pypy/changeset/e7c8a2c8d8e8/
Log: add faulthandler.dump_traceback(). Not too difficult.
diff --git a/pypy/module/faulthandler/__init__.py
b/pypy/module/faulthandler/__init__.py
--- a/pypy/module/faulthandler/__init__.py
+++ b/pypy/module/faulthandler/__init__.py
@@ -9,4 +9,6 @@
'disable': 'interp_faulthandler.disable',
'is_enabled': 'interp_faulthandler.is_enabled',
'register': 'interp_faulthandler.register',
+
+ 'dump_traceback': 'interp_faulthandler.dump_traceback',
}
diff --git a/pypy/module/faulthandler/interp_faulthandler.py
b/pypy/module/faulthandler/interp_faulthandler.py
--- a/pypy/module/faulthandler/interp_faulthandler.py
+++ b/pypy/module/faulthandler/interp_faulthandler.py
@@ -1,3 +1,8 @@
+import os
+
+from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
+
+
class FatalErrorState(object):
def __init__(self, space):
self.enabled = False
@@ -13,3 +18,28 @@
def register(space, __args__):
pass
+
+
+@unwrap_spec(w_file=WrappedDefault(None),
+ w_all_threads=WrappedDefault(True))
+def dump_traceback(space, w_file, w_all_threads):
+ ec = space.getexecutioncontext()
+ ecs = space.threadlocals.getallvalues()
+
+ if space.is_none(w_file):
+ w_file = space.sys.get('stderr')
+ fd = space.c_filedescriptor_w(w_file)
+
+ frame = ec.gettopframe()
+ while frame:
+ code = frame.pycode
+ lineno = frame.get_last_lineno()
+ if code:
+ os.write(fd, "File \"%s\", line %s in %s\n" % (
+ code.co_filename, lineno, code.co_name))
+ else:
+ os.write(fd, "File ???, line %s in ???\n" % (
+ lineno,))
+
+ frame = frame.f_backref()
+
diff --git a/pypy/module/faulthandler/test/test_faulthander.py
b/pypy/module/faulthandler/test/test_faulthander.py
--- a/pypy/module/faulthandler/test/test_faulthander.py
+++ b/pypy/module/faulthandler/test/test_faulthander.py
@@ -9,3 +9,8 @@
assert faulthandler.is_enabled() is True
faulthandler.disable()
assert faulthandler.is_enabled() is False
+
+ def test_dump_traceback(self):
+ import faulthandler
+ faulthandler.dump_traceback()
+
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit