Skip to content
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

Jython: deque() does not take keyword arguments #441

Closed
eandersson opened this issue Feb 17, 2014 · 2 comments
Closed

Jython: deque() does not take keyword arguments #441

eandersson opened this issue Feb 17, 2014 · 2 comments

Comments

@eandersson
Copy link
Contributor

There is unfortunately another issue with Jython that I missed when submitting the previous fixes in #440, related to Issue #370.

Caused by this bug in Jython http://bugs.jython.org/issue1949

Traceback

Traceback (most recent call last):
  File "C:/Users/eandersson/Desktop/pika-master/test.py", line 7, in <module>
    channel = connection.channel()
  File "C:\Users\eandersson\Desktop\pika-master\pika\adapters\blocking_connection.py", line 195, in channel
    self._channels[channel_number] = BlockingChannel(self, channel_number)
  File "C:\Users\eandersson\Desktop\pika-master\pika\adapters\blocking_connection.py", line 452, in __init__
    super(BlockingChannel, self).__init__(connection, channel_number)
  File "C:\Users\eandersson\Desktop\pika-master\pika\channel.py", line 77, in __init__
    self._cancelled = collections.deque(list(), maxlen=10)
TypeError: deque() does not take keyword arguments

Possible solutions

First one way could cause unexpected behavior under Jython.

        try:
            self._cancelled = collections.deque(list(), maxlen=10)
        except TypeError:
            self._cancelled = collections.deque(list())

Second one would need to be wrapped around any append call and make it difficult to maintain the code.

if len(self._cancelled) >= 10:
    self.popleft()

Third one would need to cover all options adding to the dequeue, but most likely be the cleanest solution.

class deque_wrapper(collections.deque):
    """Compatibility wrapper around deque to fix a Jython issue.

        http://bugs.jython.org/issue1949
    """
    def __init__(self, iterable=(), maxlen=None):
        try:
            super(deque_wrapper, self).__init__(iterable, maxlen=maxlen)
        except TypeError:
            self._maxlen = maxlen
            super(deque_wrapper, self).__init__(iterable)

    def append(self, *args, **kwargs):
        if hasattr(self, '_maxlen'):
            if len(self) >= self._maxlen:
                self.popleft()
        super(deque_wrapper, self).append(*args, **kwargs)
gmr added a commit that referenced this issue Feb 17, 2014
@gmr
Copy link
Member

gmr commented Feb 17, 2014

This should address that for you, LMK.

@eandersson
Copy link
Contributor Author

Looks good thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants