mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-28 16:28:01 -05:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user