[Twisted-Python] executing .rpy in a thread

Andrew Bennetts andrew-twisted at puzzling.org
Fri Sep 12 23:51:59 EDT 2003

On Wed, Sep 03, 2003 at 11:18:37PM -0700, stephan wrote:
> Say I want to execute blocking code in a .rpy file. Can't I just execute
> all the code in a separate thread? I've found the following code to
> execute a function in a thread. How could I add a callback to that
> thread so I could get back the whole html page back from that
> "notthreadSafe" function and return it to the client (web browser)?

The easiest way to run code in a thread and get the result back is with
twisted.internet.threads.deferToThread.  Your Resource's render method would
need to return NOT_DONE_YET, and you'd need to add callbacks to the Deferred
from deferToThread that call request.write(...) and request.finish().


More information about the Twisted-Python mailing list