Skip to content

Commit 767acb1

Browse files
author
Dana Powers
committed
Improve docstrings in kafka.conn
1 parent cb31845 commit 767acb1

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

kafka/conn.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ def _read_bytes(self, num_bytes):
112112
# TODO multiplex socket communication to allow for multi-threaded clients
113113

114114
def send(self, request_id, payload):
115-
"Send a request to Kafka"
115+
"""
116+
Send a request to Kafka
117+
param: request_id -- can be any int (used only for debug logging...)
118+
param: payload -- an encoded kafka packet (see KafkaProtocol)
119+
"""
116120

117121
log.debug("About to send %d bytes to Kafka, request %d" % (len(payload), request_id))
118122

@@ -128,12 +132,14 @@ def send(self, request_id, payload):
128132

129133
def recv(self, request_id):
130134
"""
131-
Get a response from Kafka
135+
Get a response packet from Kafka
136+
param: request_id -- can be any int (only used for debug logging...)
137+
returns encoded kafka packet response from server as type str
132138
"""
133139
log.debug("Reading response %d from Kafka" % request_id)
140+
134141
# Read the size off of the header
135142
resp = self._read_bytes(4)
136-
137143
(size,) = struct.unpack('>i', resp)
138144

139145
# Read the remainder of the response
@@ -144,14 +150,15 @@ def copy(self):
144150
"""
145151
Create an inactive copy of the connection object
146152
A reinit() has to be done on the copy before it can be used again
153+
return a new KafkaConnection object
147154
"""
148155
c = copy.deepcopy(self)
149156
c._sock = None
150157
return c
151158

152159
def close(self):
153160
"""
154-
Close this connection
161+
Shutdown and close the connection socket
155162
"""
156163
log.debug("Closing socket connection for %s:%d" % (self.host, self.port))
157164
if self._sock:
@@ -172,6 +179,9 @@ def close(self):
172179
def reinit(self):
173180
"""
174181
Re-initialize the socket connection
182+
close current socket (if open)
183+
and start a fresh connection
184+
raise ConnectionError on error
175185
"""
176186
log.debug("Reinitializing socket connection for %s:%d" % (self.host, self.port))
177187

0 commit comments

Comments
 (0)