jquery-Ajax call on tornado handlers waits for pervious ajax call to return

230 views
Skip to first unread message

Harsh K

unread,
Dec 9, 2009, 3:32:49 AM12/9/09
to Tornado Web Server
Hey All.

I recently started testing TornadoWeb for a home-project, which uses
jquery getJSON function to call my tornado handlers. And found
something strange, which i seek an explanation for.

I fire an ajax request for *Handler1* on tornado, and in some cases
request for *Handler2* is initiated before *Handler1* returns. It
appears from development-server logs, and firebug console-debugging,
that *Handler2* request waits for *Handler1* request to finish, and
then return. So basically, XHR call is waiting for earlier XHRs. They
are supposed to be asynchronous/non-blocking right?? Or am i missing
something.

You can check the test-case environment called *testtornado* at
*http://github.com/harshh/Harsh-Projects/* with main.py as server
triggering file.

I would appreciate help from anyone who can throw some light on this.

Thanks.

David P. Novakovic

unread,
Dec 9, 2009, 4:48:33 AM12/9/09
to python-tornado
If Handler1 blocks, like it does a blocking request to a nother server, of an SQL query takes a long time to run, the whole server is blocked until it finishes.

In your code you are using time.sleep, which is most definitely a blocking call.

If you use the async http client to do a nonblocking request to another server that sleeps it will work. Or use the alert system in tornado (i'm not totally familiar with how it works since i've never needed it)

Jerry

unread,
Dec 9, 2009, 9:16:50 AM12/9/09
to Tornado Web Server
Yes... your ajax calls are non-blocking but you just happen to be
calling a server that itself is blocking.

Here's a link to an example of a simple Tornado program altered to
handle requests in a non-blocking way:

http://gist.github.com/246618

This was provided to me when I ran into the same problem. You set up
PeriodicCallback (from ioloop) to handle the blocking part of the
request. The request stays open as far as the client browser is
concerned. When the blocking call is ready to respond to the request,
it calls the finish() method. Just be sure to stop the scheduler, too.

On Dec 9, 3:32 am, Harsh K <simplyha...@gmail.com> wrote:
> Hey All.
>
> I recently started testing TornadoWeb for a home-project, which uses
> jquery getJSON function to call my tornado handlers. And found
> something strange, which i seek an explanation for.
>
> I fire an ajax request for *Handler1* on tornado, and in some cases
> request for *Handler2* is initiated before *Handler1* returns. It
> appears from development-server logs, and firebug console-debugging,
> that *Handler2* request waits for *Handler1* request to finish, and
> then return. So basically, XHR call is waiting for earlier XHRs. They
> are supposed to be asynchronous/non-blocking right?? Or am i missing
> something.
>
> You can check the test-case environment called *testtornado* at
> *http://github.com/harshh/Harsh-Projects/*with main.py as server
Reply all
Reply to author
Forward
0 new messages