I do know that cherrypy is a multithreaded and also has a threadpool implementation.
So I wanted to try an example showing multithreaded behaviour.
Now lets say I've my some function in the root class and rest all things are configured
def testPage(self, *args, **kwargs):
current = threading.currentThread()
print 'Starting ' , current
time.sleep(5)
print 'Ending ' ,current
return '<html>Hello World</html>'
Now lets say I run my page as http://localhost:6060/root/testPage in 3-4 tabs of browser.
What result I get is
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)>
The thing I can clearly understand that it's creating new threads for processing every new request but I cannot figure out why every time I get
starting...ending..starting..ending
and why not starting...starting..ending..ending sometimes
Because what my assumption is that time.sleep will make some thread to suspend and other one can execute at that time.