#NEWLINE# def current_bucket( self ) : #NEWLINE# #INDENT# current_time = self . time . current_time_in_millis ( ) #NEWLINE# current_bucket = self . buckets . peek_last ( ) #NEWLINE# if ( ( current_bucket is not None ) and ( current_time < ( current_bucket . window_start + self . buckets_size_in_milliseconds ( ) ) ) ) : #NEWLINE# #INDENT# return current_bucket #NEWLINE# #UNINDENT# with self . _new_bucket_lock : #NEWLINE# #INDENT# if ( self . buckets . peek_last ( ) is None ) : #NEWLINE# #INDENT# new_bucket = Bucket ( current_time , self . bucket_data_length ) #NEWLINE# self . buckets . add_last ( new_bucket ) #NEWLINE# return new_bucket #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# for i in range ( self . bucket_numbers ) : #NEWLINE# #INDENT# last_bucket = self . buckets . peek_last ( ) #NEWLINE# if ( current_time < ( last_bucket . window_start + self . buckets_size_in_milliseconds ( ) ) ) : #NEWLINE# #INDENT# return last_bucket #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( current_time - ( last_bucket . window_start + self . buckets_size_in_milliseconds ( ) ) ) > self . milliseconds ) : #NEWLINE# #INDENT# self . reset ( ) #NEWLINE# return self . current_bucket ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# all_buckets = [ b for b in self . buckets ] #NEWLINE# self . buckets . add_last ( Bucket ( ( last_bucket . window_start + self . buckets_size_in_milliseconds ( ) ) , self . bucket_data_length ) ) #NEWLINE# self . snapshot = PercentileSnapshot ( * all_buckets ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return self . buckets . peek_last ( ) #NEWLINE# #UNINDENT# #UNINDENT# current_bucket = self . buckets . peek_last ( ) #NEWLINE# if ( current_bucket is not None ) : #NEWLINE# #INDENT# return current_bucket #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# time . sleep ( 5 ) #NEWLINE# self . current_bucket ( )