[Twisted-Python] PB waitingForAnswers KeyError
William Waites
ww at groovy.net
Fri Jul 22 23:33:45 MDT 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):
result.append(res)
e.set()
def _f():
d = maybeDeferred(f, *av, **kw)
d.addBoth(_s)
reactor.callFromThread(_f, *av, **kw)
e.wait()
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.
-w
More information about the Twisted-Python
mailing list