diff --git a/kafka/consumer/group.py b/kafka/consumer/group.py index 26408c3a5..4fd57ae9c 100644 --- a/kafka/consumer/group.py +++ b/kafka/consumer/group.py @@ -651,7 +651,7 @@ def poll(self, timeout_ms=0, max_records=None, update_offsets=True): # Poll for new data until the timeout expires start = time.time() remaining = timeout_ms - while True: + while not self._closed: records = self._poll_once(remaining, max_records, update_offsets=update_offsets) if records: return records @@ -660,7 +660,9 @@ def poll(self, timeout_ms=0, max_records=None, update_offsets=True): remaining = timeout_ms - elapsed_ms if remaining <= 0: - return {} + break + + return {} def _poll_once(self, timeout_ms, max_records, update_offsets=True): """Do one round of polling. In addition to checking for new data, this does