Answer the question
In order to leave comments, you need to log in
Asynchronous requests to a Twisted application?
Hey Habr.
There is a twisted application that accesses some remote service through an external python library:
import externalLib
def render_POST(self, request):
#some code here
result = self.doQuery(...)
return json.dumps(result)
def doQuery(self, ...):
#some code
return externalLib.request()
Answer the question
In order to leave comments, you need to log in
from twisted.internet import reactor, threads
def doLongCalculation():
# .... do long calculation here ...
return 3
def printResult(x):
print x
# run method in thread and get result as defer.Deferred
d = threads.deferToThread(doLongCalculation)
d.addCallback(printResult)
reactor.run()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question