G.A.
G.A.

Reputation: 1523

Web.py: Can't get multithreaded behavior with multiple browser tabs

I heard Web.py is a multithreaded webserver by default. So created a simple application that sleeps for a minute before returning "Hello World".

Now if I call this application (i.e., http://localhost:8080/) from two different browsers almost simultaneously, I get the 'Hello World' almost simultaneously in both browsers after 60 seconds - indicating that multithreading at the Web.py end is working fine.

But if I open two tabs in same browser and call the same url almost simultaneously (a few seconds apart), I get the "Hello world" in first tab after 60 seconds as expected and then the "Hello World" in 2nd tab 60 seconds after the first response. That is total of 120 seconds. Thus indicating that Web.py did not do multithreading.

I want to eventually create a python client application (using httplib2) that will issue http requests from different threads. Those http requests from the different threads may be exactly the same. I am assuming that is more or less similar to issuing http requests from different tabs in the same browser.

Any ideas on how to get multi-threading behavior in this case ? Or what I am doing wrong? Any special configuration of web.py needed ? Or any other (simple) web framework that will do what I expect.

Upvotes: 1

Views: 1877

Answers (1)

MadDogX
MadDogX

Reputation: 347

The behaviour you describe seems to be specific to certain browsers. After taking the time to recreate your situation, i.e. creating a simple web.py application that sleeps for a while before answering a request, I was able to recreate the issue - in Firefox. Trying the same in IE8 using two tabs actually produced the originally expected result: both requests are processed simultaneously.

This leads me to believe that the problem is browser related, not an issue with web.py. Most likely, some browsers will queue requests made to the same URL or domain instead of sending them all at once.

A multithreaded or multiprocessed Python application should not suffer from the same problem.

For reference purposes, this is the simple web.py app I produced, using the basic tutorial:

#!/usr/bin/env python

import time, web

urls = (
  '/', 'index'
)

web.config.debug = False
app = web.application(urls, globals())

class index:
    def GET(self):
        time.sleep(10)
        return "Hello, world!"

if __name__ == "__main__":
    app.run()

Upvotes: 5

Related Questions