[Twisted-Python] Re: [Twisted-commits] r13295 - WSGI input/error streams, pausing when write buffer is full, and file wrapper.
Andrew Bennetts
andrew-twisted at puzzling.org
Tue Mar 22 20:09:51 EST 2005
On Tue, Mar 22, 2005 at 03:50:59PM -0700, James Knight wrote:
[...]
> +
> +def callInReactor(__f, *__a, **__kw):
> + from twisted.internet import reactor
> + queue = Queue.Queue()
> + reactor.callFromThread(__callFromThread, queue, __f, __a, __kw)
> + result = queue.get()
> + if isinstance(result, failure.Failure):
> + result.raiseException()
> + return result
> +
> +def __callFromThread(queue, f, a, kw):
> + result = defer.maybeDeferred(f, *a, **kw)
> + result.addBoth(queue.put)
I recall posting example code to do a similar job to the mailing list
recently, and also someone on the list (or irc channel?) asking how to do
this (make the thread that does callFromThread block on the result).
This should probably be turned into a proper API.
-Andrew.
More information about the Twisted-Python
mailing list