[pypy-commit] pypy stmgc-c7: Cannot call tq.number_of_transactions_executed() when running.

arigo noreply at buildbot.pypy.org
Fri Feb 20 09:14:52 CET 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: stmgc-c7
Changeset: r76006:1be37e1a9afe
Date: 2015-02-20 09:14 +0100
http://bitbucket.org/pypy/pypy/changeset/1be37e1a9afe/

Log:	Cannot call tq.number_of_transactions_executed() when running.

diff --git a/lib_pypy/pypy_test/test_transaction.py b/lib_pypy/pypy_test/test_transaction.py
--- a/lib_pypy/pypy_test/test_transaction.py
+++ b/lib_pypy/pypy_test/test_transaction.py
@@ -104,6 +104,14 @@
         raise AssertionError("should have raised NameError")
     assert tq.number_of_transactions_executed() == 4
 
+    tq.add(tq.number_of_transactions_executed)
+    try:
+        tq.run()
+    except transaction.TransactionError:
+        pass
+    else:
+        raise AssertionError("should have raised TransactionError")
+
     def add_transactions(l):
         if l:
             for x in range(l[0]):
diff --git a/lib_pypy/transaction.py b/lib_pypy/transaction.py
--- a/lib_pypy/transaction.py
+++ b/lib_pypy/transaction.py
@@ -177,7 +177,9 @@
             raise exc_type, exc_value, exc_traceback
 
     def number_of_transactions_executed(self):
-        return self._number_transactions_exec
+        if self._pending is self._deque:
+            return self._number_transactions_exec
+        raise TransactionError("TransactionQueue.run() is currently running")
 
     def _thread_runner(self, locks, lock_done_running, lock_deque,
                        exception, nb_segments):


More information about the pypy-commit mailing list