diff options
author | Max Baryshnikov <mephius@gmail.com> | 2017-02-07 22:31:06 +0300 |
---|---|---|
committer | Dana Powers <dana.powers@gmail.com> | 2017-03-07 13:31:46 -0800 |
commit | 5a0e9715f45b62cfe43e6873b8828f49ab73f710 (patch) | |
tree | 8c6c47fdc7997b7fcefa6a1a92386a40d6ab9773 /kafka/protocol/struct.py | |
parent | 82d50f443e04356b2f051f7476bb4b4f5bd700d2 (diff) | |
download | kafka-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.py | 6 |
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 |