def eventloop(conn, limit=None, timeout=None, ignore_timeouts=False):
    for i in limit and range(limit) or count():
        try:
            yield conn.drain_events(timeout=timeout)
        except socket.timeout:
            if timeout and not ignore_timeouts:  # pragma: no cover
                raise
Best practice generator wrapper around ``Connection.drain_events``.
dataset/ETHPy150Open celery/kombu/kombu/common.py/eventloop