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

dbusCaller=None + defer.inlineCallbacks silently does not work #21

Open
socketpair opened this issue Nov 20, 2014 · 5 comments
Open

dbusCaller=None + defer.inlineCallbacks silently does not work #21

socketpair opened this issue Nov 20, 2014 · 5 comments

Comments

@socketpair
Copy link

This does not work (prints None) silently and does not even say that something wrong.

class MyObj(objects.DBusObject):
    ...
    @defer.inlineCallbacks
    def dbus_identTest(self, dbusCaller=None):
        print 'Caller:', dbusCaller
@cocagne
Copy link
Owner

cocagne commented Nov 21, 2014

That's probably because you're using the @defer.inlineCallbacks decorator
on a non-generator function. I've been bitten by that myself and the error
messaging stinks. Try adding "yield None" on the last line of the function.

On Thu, Nov 20, 2014 at 3:02 PM, Коренберг Марк [email protected]
wrote:

This does not work (prints None) silently and does not even say that
something wrong.

class MyObj(objects.DBusObject):
...
@defer.inlineCallbacks
def dbus_identTest(self, dbusCaller=None):
print 'Caller:', dbusCaller


Reply to this email directly or view it on GitHub
#21.

@socketpair
Copy link
Author

No, this does not work even with yield None.
I have checked in debugger: it uses inspect module, and in this case, it unable to detect that I use dbusCaller argument. I use:

  • Python 2.7.6
  • Twisted 14.0.2
  • txdbus 1.0.10

Why? Because inspect see decorated function (instead of real) which does not have dbusCaller. To prove that, I have written decorator:

def asd(fun):
    def x(self, dbusCaller=None, *args, **kwargs):
        return fun(self, *args, dbusCaller=dbusCaller, **kwargs)
    return x

and use it like this:

@asd
@defer.inlineCallbacks
def dbus_identTest(self, dbusCaller=None):
    print 'uid:', (yield self.getConnection().getConnectionUnixUser(dbusCaller))

And this works!

@socketpair
Copy link
Author

I don't understand why such functions are marked in this odd way, and also requiring to use inspect module... Why not to implement Method('identTest', caller_argument='xxx') ? this also will not break old applications

@cocagne
Copy link
Owner

cocagne commented Nov 21, 2014

Oh I see. It's probably because of the function decorator. The inspect
module will be looking for a dbusCaller argument in the wrapper function,
not the original method. That could probably be worked around, particularly
for inlineCallbacks given how common it is.

On Fri, Nov 21, 2014 at 2:15 PM, Коренберг Марк [email protected]
wrote:

I don't understand why such functions are marked in this way. Why not to
implement Method('identTest', caller_argument='xxx') ? this also will not
break old applications


Reply to this email directly or view it on GitHub
#21 (comment).

@socketpair
Copy link
Author

Did not understood:

That could probably be worked around, particularly for inlineCallbacks given how common it is.

Can you implement Method('identTest', caller_argument='xxx') ?

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