Add a few extra docstring comments about thread-safe clients/connections

This commit is contained in:
Dana Powers
2015-06-08 17:25:45 -07:00
parent c0fb0de7c4
commit 0dc6663d24
3 changed files with 12 additions and 5 deletions

View File

@@ -254,8 +254,11 @@ class KafkaClient(object):
def copy(self):
"""
Create an inactive copy of the client object
A reinit() has to be done on the copy before it can be used again
Create an inactive copy of the client object, suitable for passing
to a separate thread.
Note that the copied connections are not initialized, so reinit() must
be called on the returned copy.
"""
c = copy.deepcopy(self)
for key in c.conns:

View File

@@ -161,9 +161,11 @@ class KafkaConnection(local):
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
return a new KafkaConnection object
Create an inactive copy of the connection object, suitable for
passing to a background thread.
The returned copy is not connected; you must call reinit() before
using.
"""
c = copy.deepcopy(self)
# Python 3 doesn't copy custom attributes of the threadlocal subclass

View File

@@ -206,6 +206,8 @@ class Producer(object):
Arguments:
client (KafkaClient): instance to use for broker communications.
If async=True, the background thread will use client.copy(),
which is expected to return a thread-safe object.
codec (kafka.protocol.ALL_CODECS): compression codec to use.
req_acks (int, optional): A value indicating the acknowledgements that
the server must receive before responding to the request,