Cherrypy multithreading example

I know that cherrypy is multithreaded and also has a threadpool implementation.
So I wanted to try an example that demonstrates multithreading.
Now let's say that I have some kind of function in the root class and everyone else is configured.

def testPage(self, *args, **kwargs): current = threading.currentThread() print 'Starting ' , current time.sleep(5) print 'Ending ' ,current return '<html>Hello World</html>' 

Now let's say that I launched my page as http: // localhost: 6060 / root / testPage in 3-4 browser tabs.
What result do I get:

 Starting <WorkerThread(CP WSGIServer Thread-10, started 4844)> Ending <WorkerThread(CP WSGIServer Thread-10, started 4844)> Starting <WorkerThread(CP WSGIServer Thread-7, started 4841)> Ending <WorkerThread(CP WSGIServer Thread-7, started 4841)> Starting <WorkerThread(CP WSGIServer Thread-10, started 4844)> Ending <WorkerThread(CP WSGIServer Thread-10, started 4844)> 

I can clearly understand that it creates new threads to handle each new request, but I cannot understand why every time I get
start ... end..starting..ending
and why not get started ... get started .. indexing sometimes
Since my assumption is that time.sleep will cause some thread to pause, while another may be running at that time.

+6
python multithreading cherrypy
source share
1 answer

This is almost certainly a limitation of your browser, not CherryPy. For example, Firefox 2 will execute no more than two simultaneous requests in the same domain, even with multiple tabs. And if each tab also extracts icons ... that leave one hit at a time on your handler.

See http://www.cherrypy.org/ticket/550 for a ticket with similar source code and longer proof.

+2
source share

All Articles