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.
python multithreading cherrypy
Prahlad
source share