Skip to content

It appears that producer does not flush its buffer at exit #524

@Pehat

Description

@Pehat

Hi,
it's not actually an issue but rather a feature request. I have the following code:

#!/usr/local/bin/python3
from kafka import KafkaProducer

producer = KafkaProducer(bootstrap_servers=["10.20.30.40:5060"])
for i in range(1000):
    producer.send('topic', key=i.to_bytes(), value=i.to_bytes())
# that's all

When consumer reads the topic, it gets no messages. I've made an investigation and found that the reason is producer does not flush its message buffer before the script terminates. Appending producer.flush() to the script solves my problem, but not in all cases. For example, what if I've got an unhandled exception and flushing does not happen? Please consider handling KafkaProducer.__del__() and/or using KafkaProducer via the context (with statement).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions