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

Issue using partials in Queue.consume() #92

Open
bstempi opened this issue Jan 3, 2017 · 2 comments
Open

Issue using partials in Queue.consume() #92

bstempi opened this issue Jan 3, 2017 · 2 comments

Comments

@bstempi
Copy link

bstempi commented Jan 3, 2017

Hi,
I have some consumer callback function that looks like this:

def consume(msg, something_extra):
    print('Message: {}, extra context: {}'.format(msg.body, something_extra))

Somewhere else, I have something like this:

consumer_partial = functools.partial(consume, something_extra='xyz')
consumer = yield from queue.consume(consumer_partial)

For whatever reason, the callback is never invoked. If I pass a regular function, it works. It does not seem to work with a partial and I get no exceptions.

Any ideas?

@bstempi
Copy link
Author

bstempi commented Jan 3, 2017

Update: This seems to happen if the function that I'm trying to modify is within a class. For example:

class Something(object):

    queue = magica_queue()

    def setup_consumer(self):
        def consume(msg):
            print(msg.body)

        consumer = yield from queue.consume(consume)

This also fails.

@romantolkachyov
Copy link
Contributor

Seems like you missed something in handler declaration (I'm failed with self when I've got errors in this case). My working code:

    async def handle_message(self, message):  # it is a handler for other queue in my case
        handler = functools.partial(self.app.delivery_handler, queue.name)
        await queue.consume(handler)
    def delivery_handler(self, queue_name, message):
        ...

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