<commit_before>"""Handle AMQP Heartbeats"""
import logging

from pika import frame

LOGGER = logging.getLogger(__name__)


class HeartbeatChecker(object):
    """Sends heartbeats to the broker and checks to make sure that the broker's
    heartbeat is received before the expected timeout expires.

    """
    # Note: even though we're sending heartbeats in half the specified
    # timeout value, the broker will be sending them to us at the specified
    # value. This means we'll be checking for an idle connection via send_and_check
    # twice as many times as the broker will send heartbeats to us,
    # so we need to set max idle count to 4 here
    _MAX_IDLE_COUNT = 4
    _CONNECTION_FORCED = 320
    _STALE_CONNECTION = "Too Many Missed Heartbeats, No reply in %i seconds"

    def __init__(self, connection, timeout):
        """Create a heartbeat on the connection that sends two heartbeat frames
        within the specified timeout window. Also checks to ensure heartbeats
        are received from the broker.

        :param pika.connection.Connection: Connection object
        :param int timeout: Heartbeat check timeout. Note: heartbeats will
                            actually be sent at timeout / 2 frequency.

        """
        self._connection = connection

        # Note: see the following document:
        # https://www.rabbitmq.com/heartbeats.html#heartbeats-timeout
        self._timeout = timeout
        self._check_interval = float(self._timeout / 2)

        # Initialize counters
        self._bytes_received = 0
        self._bytes_sent = 0
        self._heartbeat_frames_received = 0
        self._heartbeat_frames_sent = 0
        self._idle_byte_intervals = 0

        # The handle for the last timer
        self._timer = None

        # Setup the timer to fire in _interval seconds
        self._setup_timer()
<commit_msg>PR review change<commit_after>"""Handle AMQP Heartbeats"""
import logging

from pika import frame

LOGGER = logging.getLogger(__name__)


class HeartbeatChecker(object):
    """Sends heartbeats to the broker and checks to make sure that the broker's
    heartbeat is received before the expected timeout expires.

    """
    # Note: even though we're sending heartbeats in half the specified
    # timeout value, the broker will be sending them to us at the specified
    # value. This means we'll be checking for an idle connection via send_and_check
    # twice as many times as the broker will send heartbeats to us,
    # so we need to set max idle count to 4 here
    _MAX_IDLE_COUNT = 4
    _CONNECTION_FORCED = 320
    _STALE_CONNECTION = "Too Many Missed Heartbeats, No reply in %i seconds"

    def __init__(self, connection, timeout):
        """Create a heartbeat on the connection that sends two heartbeat frames
        within the specified timeout window. Also checks to ensure heartbeats
        are received from the broker.

        :param pika.connection.Connection: Connection object
        :param int timeout: Heartbeat check timeout. Note: heartbeats will
                            actually be sent at timeout / 2 frequency.

        """
        self._connection = connection

        # Note: see the following document:
        # https://www.rabbitmq.com/heartbeats.html#heartbeats-timeout
        self._timeout = timeout
        self._check_interval = float(self._timeout) / 2

        # Initialize counters
        self._bytes_received = 0
        self._bytes_sent = 0
        self._heartbeat_frames_received = 0
        self._heartbeat_frames_sent = 0
        self._idle_byte_intervals = 0

        # The handle for the last timer
        self._timer = None

        # Setup the timer to fire in _interval seconds
        self._setup_timer()

{'fraction_non_alphanumeric': 0.056699652313452795, 'fraction_numerical': 0.006418828563787109, 'mean_word_length': 2.6559139784946235, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1308513', 'n_tokens_mistral': 1007, 'n_tokens_neox': 948, 'n_words': 398}