Skip to content

Commit

Permalink
Stopping daemonized threads when references to these threads are lost
Browse files Browse the repository at this point in the history
  • Loading branch information
chmduquesne committed Mar 2, 2015
1 parent 9ad0be6 commit 0497924
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
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()

0 comments on commit 0497924

Please sign in to comment.