summaryrefslogtreecommitdiff
path: root/kafka/conn.py
diff options
context:
space:
mode:
authorMahendra M <mahendra.m@gmail.com>2013-10-07 20:29:35 -0700
committerMahendra M <mahendra.m@gmail.com>2013-10-07 20:29:35 -0700
commit92d70e7310b5519a1be86f189a4ddb9d772a0434 (patch)
treeb43b90fcdaaef0839329b20a02c79f8229773b26 /kafka/conn.py
parenteb2c1735f26ce11540fb92ea94817f43b9b3a798 (diff)
parentf9cf62816ff2c2255d414a2d9f3dd32d8c81418b (diff)
downloadkafka-python-92d70e7310b5519a1be86f189a4ddb9d772a0434.tar.gz
Merge pull request #61 from mahendra/prod-windows
Ensure that async producer works in windows. Fixes #46
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)