summaryrefslogtreecommitdiff
path: root/kafka/protocol/struct.py
diff options
context:
space:
mode:
authorMax Baryshnikov <mephius@gmail.com>2017-02-07 22:31:06 +0300
committerDana Powers <dana.powers@gmail.com>2017-03-07 13:31:46 -0800
commit5a0e9715f45b62cfe43e6873b8828f49ab73f710 (patch)
tree8c6c47fdc7997b7fcefa6a1a92386a40d6ab9773 /kafka/protocol/struct.py
parent82d50f443e04356b2f051f7476bb4b4f5bd700d2 (diff)
downloadkafka-python-5a0e9715f45b62cfe43e6873b8828f49ab73f710.tar.gz
Fixed couple of "leaks" when gc is disabled (#979)
Diffstat (limited to 'kafka/protocol/struct.py')
-rw-r--r--kafka/protocol/struct.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/kafka/protocol/struct.py b/kafka/protocol/struct.py
index a3d28d7..4c1afcb 100644
--- a/kafka/protocol/struct.py
+++ b/kafka/protocol/struct.py
@@ -5,6 +5,8 @@ from io import BytesIO
from .abstract import AbstractType
from .types import Schema
+from ..util import WeakMethod
+
class Struct(AbstractType):
SCHEMA = Schema()
@@ -19,7 +21,9 @@ class Struct(AbstractType):
self.__dict__.update(kwargs)
# overloading encode() to support both class and instance
- self.encode = self._encode_self
+ # Without WeakMethod() this creates circular ref, which
+ # causes instances to "leak" to garbage
+ self.encode = WeakMethod(self._encode_self)
@classmethod
def encode(cls, item): # pylint: disable=E0202