Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

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.
  • Loading branch information...
commit c46cfb991845003822d9d40616a6efabb499b662 1 parent 37a4766
@spladug spladug authored
Showing with 6 additions and 2 deletions.
  1. +6 −2 r2/r2/lib/
8 r2/r2/lib/
@@ -53,8 +53,12 @@ def record(self, key, service_time_sec):
def flush(self):
"""Yields accumulated timing and counter data and resets the buffer."""
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

0 comments on commit c46cfb9

Please sign in to comment.
Something went wrong with that request. Please try again.