Skip to content

Commit 0dc6663

Browse files
author
Dana Powers
committed
Add a few extra docstring comments about thread-safe clients/connections
1 parent c0fb0de commit 0dc6663

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

kafka/client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,11 @@ def close(self):
254254

255255
def copy(self):
256256
"""
257-
Create an inactive copy of the client object
258-
A reinit() has to be done on the copy before it can be used again
257+
Create an inactive copy of the client object, suitable for passing
258+
to a separate thread.
259+
260+
Note that the copied connections are not initialized, so reinit() must
261+
be called on the returned copy.
259262
"""
260263
c = copy.deepcopy(self)
261264
for key in c.conns:

kafka/conn.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,11 @@ def recv(self, request_id):
161161

162162
def copy(self):
163163
"""
164-
Create an inactive copy of the connection object
165-
A reinit() has to be done on the copy before it can be used again
166-
return a new KafkaConnection object
164+
Create an inactive copy of the connection object, suitable for
165+
passing to a background thread.
166+
167+
The returned copy is not connected; you must call reinit() before
168+
using.
167169
"""
168170
c = copy.deepcopy(self)
169171
# Python 3 doesn't copy custom attributes of the threadlocal subclass

kafka/producer/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ class Producer(object):
206206
207207
Arguments:
208208
client (KafkaClient): instance to use for broker communications.
209+
If async=True, the background thread will use client.copy(),
210+
which is expected to return a thread-safe object.
209211
codec (kafka.protocol.ALL_CODECS): compression codec to use.
210212
req_acks (int, optional): A value indicating the acknowledgements that
211213
the server must receive before responding to the request,

0 commit comments

Comments
 (0)