[Twisted-Python] Perspective broker and inlineCallbacks exception handling problem

Maik Friedmann maik.friedmann at googlemail.com
Tue Jan 6 05:43:58 EST 2009

Hello Again,

> The first thing to say is that you shouldn't send us pseudo code. It will
> help you understand what's going on if you write a small example and play
> with it. And that will help us help you because we'll be able to see
> exactly what's going on and run your code ourselves.

That is right, hopefully this new mail will explain what am I asking.

> Note that in the above snippet, you're using inlineCallbacks but you're not
> yielding anything. If you try calling this main() function, it will give
> you an exception: Failure instance: Traceback: <type
> 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'send'
> That's just an example of the subtleties (and it's not so sublte in this
> case), and underlines why you should send us real code.
> Are you actually trying to call main()?

You are right again, my mistake.

Anyway, I tried running the code you wrote and it works as expected.
My problem is handling exceptions raised on remote calls (via pb).
Attached three scripts are:

server.py: Server implementation, a basic perspective broker example
that includes a custom checker, which in turn uses inlineCallbacks.
client1.py: Client implementation 1, uses inlineCallbacks
client2.py: Client implementation 2, uses plain deferreds

Clients should be same in functionality AFAIK (noting that I am new to
inlineCallbacks). Both clients have wrong passwords configured, so
that they will fail in checker with a custom exception derived from

My problem is, with the plain deferred version (client2.py), it is
easy to handle (inspect) the error in a errback since I got a Failure
object. However, for inline callbacks, the only way I can catch the
error is using this ugly code (copied from client1.py):

            ... (pb related calls)
            print 'Login Failed:',
            print sys.exc_info()[0]

Even this does not catch the error:

            ... (pb related calls)
        except Exception, e:
            print 'Login Failed:',
            print sys.exc_info()[0]

Furthermore, inlineCallbacks version also prints this deprecation warning:

DeprecationWarning: raising string exceptions is deprecated
  return g.throw(self.type, self.value, self.tb)

Is there a better way to do this, or am I missing something? BTW I am
running this on a Ubuntu 8.10 (Twisted 8.1).

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: server.py
Url: http://twistedmatrix.com/pipermail/twisted-python/attachments/20090106/699fea36/attachment.txt 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: client1.py
Url: http://twistedmatrix.com/pipermail/twisted-python/attachments/20090106/699fea36/attachment-0001.txt 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: client2.py
Url: http://twistedmatrix.com/pipermail/twisted-python/attachments/20090106/699fea36/attachment-0002.txt 

More information about the Twisted-Python mailing list