Fix race condition in stats flushing.

Some threads are writing to the data buffer while we're trying to
iterate over it. This will cause some lost stats, but no more than we're
currently losing to the app dying when it hits the race condition.
This commit is contained in:
Neil Williams
2013-01-02 18:23:14 -08:00
parent 3ada3aa4be
commit b7f7faa0ec

View File

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