[Twisted-Python] executing .rpy in a thread
stephan
ccom at gmx.net
Thu Sep 4 00:18:37 MDT 2003
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)?
from twisted.internet import reactor
from twisted.python import threadable
threadable.init(1)
def notThreadSafe(x):
"""do something that isn't thread-safe"""
# ...
def threadSafeScheduler():
"""Run in thread-safe manner."""
reactor.callFromThread(notThreadSafe, 3) # will run
'notThreadSafe(3)'
# in the event loop
_stephan
More information about the Twisted-Python
mailing list