[Twisted-Python] PB waitingForAnswers KeyError

William Waites ww at groovy.net
Sat Jul 23 01:33:45 EDT 2005

On Fri, Jul 22, 2005 at 02:19:25PM -1000, Bob Ippolito wrote:
> You've misunderstood what the example is trying to demonstrate, it is  
> not a magical "invert twisted" box. 

A magical "invert twisted" box... How about something like this?

def invert(f):
    def _i(f, *av, **kw)
        e = Event()
        result = []
        def _s(res):
        def _f():
            d = maybeDeferred(f, *av, **kw)
        reactor.callFromThread(_f, *av, **kw)

        res = result[0]
        if isinstance(res, Exception):
            raise res
        return res
    return _i

class InvertedClass:
    def fooMethod(self, ...):
        ... do twisted stuff
    fooMethod = invert(fooMethod)

Maybe with magic getattr functions it could be made completely
transparent... Not sure if it is worth the bother though.

If I am careful to do this sort of manipulation to protect potentially
dangerous code, it seems like the problems with pb disappear...

Thanks for your insight.


More information about the Twisted-Python mailing list