Skip to content
6 changes: 5 additions & 1 deletion kafka/protocol/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#from collections import namedtuple
from io import BytesIO

from kafka.util import WeakMethod

from .abstract import AbstractType
from .types import Schema

Expand All @@ -20,7 +22,9 @@ def __init__(self, *args, **kwargs):
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
Expand Down
3 changes: 2 additions & 1 deletion kafka/vendor/selectors34.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ def __iter__(self):
return iter(self._selector._fd_to_key)


class BaseSelector(six.with_metaclass(ABCMeta)):
@six.add_metaclass(ABCMeta)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same re: vendored library. Can you check with upstream version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request to vendored library: berkerpeksag/selectors34#7

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upstream merged pull request.

class BaseSelector(object):
"""Selector abstract base class.

A selector supports registering file objects to be monitored for specific
Expand Down
4 changes: 3 additions & 1 deletion kafka/vendor/six.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ def __len__(self):
else:
# 64-bit
MAXSIZE = int((1 << 63) - 1)
del X

# Don't del it here, cause with gc disabled this "leaks" to garbage
# del X
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one is a vendored library, and I really would prefer fixing upstream. otherwise I'm likely to forget and overwrite when I import a newer version. Have you checked if this is fixed already in six?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upstream doesn't have this fix, but I've filed a pull request: benjaminp/six#176



def _add_doc(func, doc):
Expand Down