[Twisted-web] xmlrpc blocking

Paul Warren u3292467 at anu.edu.au
Mon Jul 25 03:45:28 MDT 2005


Rasjid Wilcox wrote:
> Hi,
> 
> 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"
>    sleep(5)
>    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?
> 
> Thanks,
> 
> Rasjid.
>

For blocking code, you don't want to use defer.succeed()

   something like:

def xmlrpc_test(self):
	d = threads.deferToThread(test,'Hello')
	d.addCallback(_cb)
  	return d

def _cb(self, *args):
	print "Blocking call finished"
	print args

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.
-- 
Paul Warren
ANU Supercomputer facility, Access Grid Projects.
u3292467 at anu dot edu dot au
pwarren.homelinux.org



More information about the Twisted-web mailing list