Picon

Assync method on render_POST(self,request)

My code looks like this:

... # class Site(Resource)
def render_POST(self,request)
   otherclass
.doAssync(request.args)
   
print '1'
   
return "done" #that returns the HTTP response, always the same.

...
def doAssync(self,msg):
    d
= defer.Deferred()
    reactor
.callLater(0,self.doStuff,d,msg)
    d
.addCallback(self.sucess)

def doStuff(self,d,msg):
   
# do some stuff
    time
.sleep(2)  #just for example
    d
.callback('ok')

def sucess(msg):
   
print msg

The output:

1

ok

So far, so good, but, the HTTP response (return 'done'), only happens after the delay (time.sleep(2)). I can tell this, because the browser keeps 'loading' for 2 seconds.

What am I doing wrong?

Found some answer saying that wsgi twisted does not suport assync, and maybe Tornado could do this. ... is that true?

Thanks anyway!

Att,


--
João Ricardo Mattos e Silva

Graduando em Ciência da Computação na Universidade Federal de Santa Catarina

Cel: +55 (48) 96190063  |  Skype: jricardomsilva  |  Msn: joaoricardo <at> globalite.com.br
_______________________________________________
Twisted-web mailing list
Twisted-web <at> twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
exarkun | 16 Feb 2012 13:54

Re: Assync method on render_POST(self,request)

On 12:26 pm, joaoricardo000 <at> gmail.com wrote:
>[snip]
>
>def doStuff(self,d,msg):
>    # do some stuff
>    time.sleep(2)  #just for example
>    d.callback('ok')
>
>[snip]
>So far, so good, but, the HTTP response (return 'done'), only happens 
>after
>the delay (time.sleep(2)). I can tell this, because the browser keeps
>'loading' for 2 seconds.
>
>What am I doing wrong?

Answered on Stack Overflow:

http://stackoverflow.com/questions/9310350/twisted-non-blocking-method- 
how-to
>Found some answer saying that wsgi twisted does not suport assync, and
>maybe Tornado could do this. ... is that true?

By definition, WSGI applications are not asynchronous.  However, your 
code is not a WSGI application, so the nature of WSGI applications is 
irrelevant.

Tornado doesn't change these facts.  WSGI for Tornado is the same as 
WSGI for anything else.

Jean-Paul
Picon

Re: Assync method on render_POST(self,request)

Thanks for the answer, really helped, but I'm stuck again in other case.

I'm using mod_wsgi now, and I'm really lost about how to use twisted methods.

Thanks again!




2012/2/16 <exarkun <at> twistedmatrix.com>
On 12:26 pm, joaoricardo000 <at> gmail.com wrote:
>[snip]
>
>def doStuff(self,d,msg):
>    # do some stuff
>    time.sleep(2)  #just for example
>    d.callback('ok')
>
>[snip]
>So far, so good, but, the HTTP response (return 'done'), only happens
>after
>the delay (time.sleep(2)). I can tell this, because the browser keeps
>'loading' for 2 seconds.
>
>What am I doing wrong?

Answered on Stack Overflow:

http://stackoverflow.com/questions/9310350/twisted-non-blocking-method-
how-to
>Found some answer saying that wsgi twisted does not suport assync, and
>maybe Tornado could do this. ... is that true?

By definition, WSGI applications are not asynchronous.  However, your
code is not a WSGI application, so the nature of WSGI applications is
irrelevant.

Tornado doesn't change these facts.  WSGI for Tornado is the same as
WSGI for anything else.

Jean-Paul

_______________________________________________
Twisted-web mailing list
Twisted-web <at> twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web



--
João Ricardo Mattos e Silva

Graduando em Ciência da Computação na Universidade Federal de Santa Catarina

Cel: +55 (48) 96190063  |  Skype: jricardomsilva  |  Msn: joaoricardo <at> globalite.com.br
_______________________________________________
Twisted-web mailing list
Twisted-web <at> twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web

Gmane