diff options
| author | Dana Powers <dana.powers@gmail.com> | 2016-04-07 21:53:52 -0700 | 
|---|---|---|
| committer | Dana Powers <dana.powers@gmail.com> | 2016-04-08 09:21:20 -0700 | 
| commit | e86b6d21bea284097398076e059f62eb53a896ca (patch) | |
| tree | 96beaaeb287bf5e8ce9ab72c3db6bf2ecf4fb7a1 /kafka/client.py | |
| parent | 116e634e4b3fddb3e9387e20c676aea6a74afbcc (diff) | |
| download | kafka-python-e86b6d21bea284097398076e059f62eb53a896ca.tar.gz | |
Raise ConnectionError immediately on disconnect in SimpleClient._get_conn
Diffstat (limited to 'kafka/client.py')
| -rw-r--r-- | kafka/client.py | 9 | 
1 files changed, 8 insertions, 1 deletions
diff --git a/kafka/client.py b/kafka/client.py index 6a1a63b..891ae03 100644 --- a/kafka/client.py +++ b/kafka/client.py @@ -67,11 +67,18 @@ class SimpleClient(object):              )          conn = self._conns[host_key] +        conn.connect() +        if conn.connected(): +            return conn +          timeout = time.time() + self.timeout -        while time.time() < timeout: +        while time.time() < timeout and conn.connecting():              if conn.connect() is ConnectionStates.CONNECTED:                  break +            else: +                time.sleep(0.05)          else: +            conn.close()              raise ConnectionError("%s:%s (%s)" % (host, port, afi))          return conn  | 
