Author: Armin Rigo <[email protected]>
Branch: stm-thread-2
Changeset: r61621:8d8fb39ff944
Date: 2013-02-22 17:49 +0100
http://bitbucket.org/pypy/pypy/changeset/8d8fb39ff944/

Log:    Write the traceback-on-abort logic. The lnotab handling needs
        fixing.

diff --git a/lib_pypy/transaction.py b/lib_pypy/transaction.py
--- a/lib_pypy/transaction.py
+++ b/lib_pypy/transaction.py
@@ -12,7 +12,7 @@
 """
 
 from __future__ import with_statement
-import sys, thread, collections
+import sys, thread, collections, cStringIO, linecache
 
 try:
     from __pypy__.thread import atomic
@@ -218,14 +218,16 @@
         # this is a staticmethod in order to make sure that we don't
         # accidentally use 'self' in the atomic block.
         try:
-            with signals_enabled:
-                with atomic:
-                    if got_exception:
-                        return    # return early if already an exc. to reraise
-                    info = last_abort_info()
-                    if info is not None:
-                        print info
-                    f(*args, **kwds)
+            while True:
+                with signals_enabled:
+                    with atomic:
+                        info = last_abort_info()
+                        if info is None:
+                            if not got_exception:
+                                f(*args, **kwds)
+                            # else return early if already an exc to reraise
+                            return
+                report_abort_info(info)
         except:
             got_exception[:] = sys.exc_info()
 
@@ -241,3 +243,31 @@
         self.pending = collections.deque()
 
 _thread_local = _ThreadLocal()
+
+
+def report_abort_info(info):
+    header = info[0]
+    f = cStringIO.StringIO()
+    if len(info) > 1:
+        print >> f, 'Traceback from detected conflict:'
+        for tb in info[1:]:
+            filename = tb[0]
+            coname = tb[1]
+            lineno = tb[2]
+            lnotab = tb[3]
+            bytecodenum = tb[-1]
+            for i in range(0, len(lnotab), 2):
+                if bytecodenum < 0:
+                    break
+                bytecodenum -= ord(lnotab[i])
+                lineno += ord(lnotab[i+1])
+            print >> f, '  File "%s", line %d, in %s' % (
+                filename, lineno, coname)
+            line = linecache.getline(filename,lineno)
+            if line: print >> f, '    ' + line.strip()
+    print >> f, 'Transaction aborted, %g seconds lost (th%d' % (
+        header[0] * 1E-9, header[2]),
+    print >> f, 'abrt%d %s%s%d/%d)' % (
+        header[1], 'atom '*header[3], 'inev '*(header[4]>1),
+        header[5], header[6])
+    sys.stderr.write(f.getvalue())
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to