summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDana Powers <dana.powers@rd.io>2016-01-08 15:47:37 -0800
committerDana Powers <dana.powers@rd.io>2016-01-10 21:23:38 -0800
commit1fd596062fba5ce4236623249ffafcf0be985282 (patch)
tree87fcaf32ff46252ac0d7c165e2fa3004bf64fecf
parent5d2886bae36c8336a15e0f58c827556de186350a (diff)
downloadkafka-python-1fd596062fba5ce4236623249ffafcf0be985282.tar.gz
Avoid CPU spinnning when there are no sockets to read
-rw-r--r--kafka/client_async.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/kafka/client_async.py b/kafka/client_async.py
index 1c74c6f..fa498e9 100644
--- a/kafka/client_async.py
+++ b/kafka/client_async.py
@@ -334,6 +334,14 @@ class KafkaClient(object):
if (conn.state is ConnectionStates.CONNECTED
and conn.in_flight_requests)])
if not sockets:
+ # if sockets are connecting, we can wake when they are writeable
+ if self._connecting:
+ sockets = [self._conns[node]._sock for node in self._connecting]
+ select.select([], sockets, [], timeout)
+ # otherwise just sleep to prevent CPU spinning
+ else:
+ log.debug('Nothing to do in _poll -- sleeping for %s', timeout)
+ time.sleep(timeout)
return []
ready, _, _ = select.select(list(sockets.keys()), [], [], timeout)