[Twisted-web] xmlrpc blocking
u3292467 at anu.edu.au
Mon Jul 25 03:45:28 MDT 2005
Rasjid Wilcox wrote:
> I've gone through all the xmlrpc examples I can find, and I see the use of
> 'defer.succeed(...)', but I'm clearly not understanding something.
> When I run some code that blocks, the whole server stops responding.
> I have:
> def test(foo):
> print "start test"
> print foo
> print "finish test"
> return 'Success'
> class Echoer(xmlrpc.XMLRPC):
> def xmlrpc_test(self):
> return defer.succeed(test('hello'))
> What should I be doing instead?
For blocking code, you don't want to use defer.succeed()
d = threads.deferToThread(test,'Hello')
def _cb(self, *args):
print "Blocking call finished"
is what you want.
The idea is to write non-blocking stuff if at all possible. But if you
can't, do it a different thread, and have callbacks (and error backs)
At least, that is the conclusion (confusion??) I've come to after
spending six months writing a fairly large twisted project interacting
with real-life hardware (http://agcentral.org/downloads/agdevicecontrol
if you're interested.
Hope that helps.
ANU Supercomputer facility, Access Grid Projects.
u3292467 at anu dot edu dot au
More information about the Twisted-web