txdbus icon indicating copy to clipboard operation
txdbus copied to clipboard

dbusCaller=None + defer.inlineCallbacks silently does not work

Open socketpair opened this issue 9 years ago • 5 comments

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

socketpair avatar Nov 20 '14 21:11 socketpair

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 https://github.com/cocagne/txdbus/issues/21.

cocagne avatar Nov 21 '14 02:11 cocagne

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 avatar Nov 21 '14 20:11 socketpair

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

socketpair avatar Nov 21 '14 20:11 socketpair

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 https://github.com/cocagne/txdbus/issues/21#issuecomment-64031099.

cocagne avatar Nov 21 '14 21:11 cocagne

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') ?

socketpair avatar Nov 24 '14 19:11 socketpair