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

Additional callback parameters #1

Closed
bra-fsn opened this issue Nov 17, 2012 · 2 comments
Closed

Additional callback parameters #1

bra-fsn opened this issue Nov 17, 2012 · 2 comments

Comments

@bra-fsn
Copy link

bra-fsn commented Nov 17, 2012

Hi,

I'm trying to set up a Queue based resolver, running in two threads:

  1. a while loop, reading a Queue(), calling channel.gethostbyname
  2. the DNS resolver thread, running pycares

To identify the original caller in the callback, I need to pass on additional parameters, but currently it's not possible.

It would be nice to have the following:

def cb(result, error, data):
    print result
    print error
    print data

channel.gethostbyname('google.com', socket.AF_INET, cb, data)

Data should be any type of python object, passed to cb as the third argument.

@saghul
Copy link
Owner

saghul commented Nov 17, 2012

Hi,

You can do that with a partial object, as follows:

from functools import partial

def cb(data, result, error):
    print data, result, error

channel.gethostbyname('google.com', socket.AF_INET, partial(cb, data))

Note that anything you pass to the partial object will come before the result and error arguments.

Is this a workable solution for you?

@bra-fsn
Copy link
Author

bra-fsn commented Nov 17, 2012

Perfectly, 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