[Piglit] [PATCH 1/3] framework.log: Replace synchronized_self decorator
Dylan Baker
baker.dylan.c at gmail.com
Tue Apr 8 14:39:08 PDT 2014
This replaces the synchronized_self decorator from piglit's threads
module with a context manager (with foo: <stuff>). This is more standard
python, and means having a little less hand rolled code around.
Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
framework/log.py | 31 ++++++++++++++++---------------
1 file changed, 16 insertions(+), 15 deletions(-)
diff --git a/framework/log.py b/framework/log.py
index d045847..03b5de7 100644
--- a/framework/log.py
+++ b/framework/log.py
@@ -22,7 +22,7 @@
import sys
import collections
-from .threads import synchronized_self
+from threading import RLock
class Log(object):
@@ -38,6 +38,7 @@ class Log(object):
self.__running = []
self.__generator = (x for x in xrange(self.__total))
self.__pad = len(str(self.__total))
+ self._lock = RLock()
self.__summary_keys = set(['pass', 'fail', 'warn', 'crash', 'skip',
'dmesg-warn', 'dmesg-fail', 'dry-run'])
self.__summary = collections.defaultdict(lambda: 0)
@@ -89,7 +90,6 @@ class Log(object):
'name': name,
'result': result}))
- @synchronized_self
def post_log(self, value, result):
""" Used to mark a test as complete in the log
@@ -98,17 +98,17 @@ class Log(object):
result -- the result of the completed test
"""
- # Mark running complete
- assert value in self.__running
- self.__running.remove(value)
+ with self.__lock:
+ # Mark running complete
+ assert value in self.__running
+ self.__running.remove(value)
- # increment the number of completed tests
- self.__complete += 1
+ # increment the number of completed tests
+ self.__complete += 1
- assert result in self.__summary_keys
- self.__summary[result] += 1
+ assert result in self.__summary_keys
+ self.__summary[result] += 1
- @synchronized_self
def log(self, name, result):
""" Print to the screen
@@ -116,10 +116,10 @@ class Log(object):
over it.
"""
- assert result in self.__summary_keys
- self.__print(name, result)
+ with self.__lock:
+ assert result in self.__summary_keys
+ self.__print(name, result)
- @synchronized_self
def pre_log(self, running=None):
""" Hook to run before log()
@@ -131,8 +131,9 @@ class Log(object):
nothing will be printed. Default: None
"""
- if running:
- self.__print(running, 'running')
+ with self.__lock:
+ if running:
+ self.__print(running, 'running')
x = self.__generator.next()
self.__running.append(x)
--
1.9.1
More information about the Piglit
mailing list