def _thread_loop(self):
last_check_time = time.time()<EOL>messages = []<EOL>while True:<EOL><INDENT>time_since_last_check = time.time() - last_check_time<EOL>time_till_next_check = max(<NUM_LIT:0>, self.interval - time_since_last_check)<EOL>try:<EOL><INDENT>message = self._queue.get(timeout=time_till_next_check)<EOL><DEDENT>except queue.Empty:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>if message is None:<EOL><INDENT>break<EOL><DEDENT>messages.append(message)<EOL>should_stop = False<EOL>while True:<EOL><INDENT>try:<EOL><INDENT>message = self._queue.get_nowait()<EOL><DEDENT>except queue.Empty:<EOL><INDENT>break<EOL><DEDENT>if message is None:<EOL><INDENT>should_stop = True<EOL>break<EOL><DEDENT>messages.append(message)<EOL><DEDENT>if should_stop:<EOL><INDENT>break<EOL><DEDENT><DEDENT>current_time = time.time()<EOL>if current_time - last_check_time >= self.interval:<EOL><INDENT>last_check_time = current_time<EOL>for i in range(<NUM_LIT:0>, len(messages), self.batch_size):<EOL><INDENT>batch = messages[i:i + self.batch_size]<EOL>self.send_socket(b'<STR_LIT>'.join(batch))<EOL><DEDENT>messages = []<EOL><DEDENT><DEDENT>for i in range(<NUM_LIT:0>, len(messages), self.batch_size):<EOL><INDENT>batch = messages[i:i + self.batch_size]<EOL>self.send_socket(b'<STR_LIT>'.join(batch))<EOL><DEDENT>
Background thread used when Sender is in asynchronous/interval mode.