stats: Another attempt at fixing the race condition in flushing.

It appears that sometimes multiple threads are flushing the same dict at
the same time. Yikes! This should fix that without double counting.
This commit is contained in:
Neil Williams
2013-01-03 12:09:21 -08:00
parent 37a476677f
commit c46cfb9918

View File

@@ -53,8 +53,12 @@ class TimingStatBuffer:
def flush(self):
"""Yields accumulated timing and counter data and resets the buffer."""
data, self.data = self.data, collections.defaultdict(complex)
while data:
k, v = data.popitem()
while True:
try:
k, v = data.popitem()
except KeyError:
break
total_time, count = v.real, v.imag
yield k, str(int(count)) + '|c'
divisor = count or 1