@@ -226,7 +226,7 @@ class Producer(object):
226
226
227
227
Arguments:
228
228
client (kafka.SimpleClient): instance to use for broker
229
- communications. If async =True, the background thread will use
229
+ communications. If async_send =True, the background thread will use
230
230
:meth:`client.copy`, which is expected to return a thread-safe
231
231
object.
232
232
codec (kafka.protocol.ALL_CODECS): compression codec to use.
@@ -238,11 +238,11 @@ class Producer(object):
238
238
sync_fail_on_error (bool, optional): whether sync producer should
239
239
raise exceptions (True), or just return errors (False),
240
240
defaults to True.
241
- async (bool, optional): send message using a background thread,
241
+ async_send (bool, optional): send message using a background thread,
242
242
defaults to False.
243
- batch_send_every_n (int, optional): If async is True, messages are
243
+ batch_send_every_n (int, optional): If async_send is True, messages are
244
244
sent in batches of this size, defaults to 20.
245
- batch_send_every_t (int or float, optional): If async is True,
245
+ batch_send_every_t (int or float, optional): If async_send is True,
246
246
messages are sent immediately after this timeout in seconds, even
247
247
if there are fewer than batch_send_every_n, defaults to 20.
248
248
async_retry_limit (int, optional): number of retries for failed messages
@@ -268,8 +268,10 @@ class Producer(object):
268
268
defaults to 30.
269
269
270
270
Deprecated Arguments:
271
+ async (bool, optional): send message using a background thread,
272
+ defaults to False. Deprecated, use 'async_send'
271
273
batch_send (bool, optional): If True, messages are sent by a background
272
- thread in batches, defaults to False. Deprecated, use 'async '
274
+ thread in batches, defaults to False. Deprecated, use 'async_send '
273
275
"""
274
276
ACK_NOT_REQUIRED = 0 # No ack is required
275
277
ACK_AFTER_LOCAL_WRITE = 1 # Send response after it is written to log
@@ -282,8 +284,8 @@ def __init__(self, client,
282
284
codec = None ,
283
285
codec_compresslevel = None ,
284
286
sync_fail_on_error = SYNC_FAIL_ON_ERROR_DEFAULT ,
285
- async = False ,
286
- batch_send = False , # deprecated, use async
287
+ async_send = False ,
288
+ batch_send = False , # deprecated, use async_send
287
289
batch_send_every_n = BATCH_SEND_MSG_COUNT ,
288
290
batch_send_every_t = BATCH_SEND_DEFAULT_INTERVAL ,
289
291
async_retry_limit = ASYNC_RETRY_LIMIT ,
@@ -292,15 +294,21 @@ def __init__(self, client,
292
294
async_queue_maxsize = ASYNC_QUEUE_MAXSIZE ,
293
295
async_queue_put_timeout = ASYNC_QUEUE_PUT_TIMEOUT ,
294
296
async_log_messages_on_error = ASYNC_LOG_MESSAGES_ON_ERROR ,
295
- async_stop_timeout = ASYNC_STOP_TIMEOUT_SECS ):
297
+ async_stop_timeout = ASYNC_STOP_TIMEOUT_SECS ,
298
+ ** kwargs ):
299
+
300
+ # async renamed async_send for python3.7 support
301
+ if 'async' in kwargs :
302
+ log .warning ('Deprecated async option found -- use async_send' )
303
+ async_send = kwargs ['async' ]
296
304
297
- if async :
305
+ if async_send :
298
306
assert batch_send_every_n > 0
299
307
assert batch_send_every_t > 0
300
308
assert async_queue_maxsize >= 0
301
309
302
310
self .client = client
303
- self .async = async
311
+ self .async_send = async_send
304
312
self .req_acks = req_acks
305
313
self .ack_timeout = ack_timeout
306
314
self .stopped = False
@@ -313,7 +321,7 @@ def __init__(self, client,
313
321
self .codec = codec
314
322
self .codec_compresslevel = codec_compresslevel
315
323
316
- if self .async :
324
+ if self .async_send :
317
325
# Messages are sent through this queue
318
326
self .queue = Queue (async_queue_maxsize )
319
327
self .async_queue_put_timeout = async_queue_put_timeout
@@ -400,7 +408,7 @@ def _send_messages(self, topic, partition, *msg, **kwargs):
400
408
if key is not None and not isinstance (key , six .binary_type ):
401
409
raise TypeError ("the key must be type bytes" )
402
410
403
- if self .async :
411
+ if self .async_send :
404
412
for idx , m in enumerate (msg ):
405
413
try :
406
414
item = (TopicPartition (topic , partition ), m , key )
@@ -435,15 +443,15 @@ def stop(self, timeout=None):
435
443
log .warning ('timeout argument to stop() is deprecated - '
436
444
'it will be removed in future release' )
437
445
438
- if not self .async :
446
+ if not self .async_send :
439
447
log .warning ('producer.stop() called, but producer is not async' )
440
448
return
441
449
442
450
if self .stopped :
443
451
log .warning ('producer.stop() called, but producer is already stopped' )
444
452
return
445
453
446
- if self .async :
454
+ if self .async_send :
447
455
self .queue .put ((STOP_ASYNC_PRODUCER , None , None ))
448
456
self .thread_stop_event .set ()
449
457
self .thread .join ()
@@ -471,5 +479,5 @@ def stop(self, timeout=None):
471
479
self .stopped = True
472
480
473
481
def __del__ (self ):
474
- if self .async and not self .stopped :
482
+ if self .async_send and not self .stopped :
475
483
self .stop ()
0 commit comments