Skip to content

Properly destroying the objects that contain daemonized threads #324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions kafka/producer/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def __init__(self, client, async=False,
self.async = async
self.req_acks = req_acks
self.ack_timeout = ack_timeout
self.stopped = False

if codec is None:
codec = CODEC_NONE
Expand Down Expand Up @@ -212,3 +213,8 @@ def stop(self, timeout=1):

if self.proc.is_alive():
self.proc.terminate()
self.stopped = True

def __del__(self):
if not self.stopped:
self.stop()
3 changes: 3 additions & 0 deletions kafka/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,6 @@ def stop(self):
# noinspection PyAttributeOutsideInit
self.timer = None
self.fn = None

def __del__(self):
self.stop()