summaryrefslogtreecommitdiff
path: root/kafka/conn.py
diff options
context:
space:
mode:
Diffstat (limited to 'kafka/conn.py')
-rw-r--r--kafka/conn.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/kafka/conn.py b/kafka/conn.py
index 9356731..14aebc6 100644
--- a/kafka/conn.py
+++ b/kafka/conn.py
@@ -1,3 +1,4 @@
+import copy
import logging
import socket
import struct
@@ -103,17 +104,27 @@ class KafkaConnection(local):
self.data = self._consume_response()
return self.data
+ def copy(self):
+ """
+ Create an inactive copy of the connection object
+ A reinit() has to be done on the copy before it can be used again
+ """
+ c = copy.deepcopy(self)
+ c._sock = None
+ return c
+
def close(self):
"""
Close this connection
"""
- self._sock.close()
+ if self._sock:
+ self._sock.close()
def reinit(self):
"""
Re-initialize the socket connection
"""
- self._sock.close()
+ self.close()
self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._sock.connect((self.host, self.port))
self._sock.settimeout(10)