CPython threading is not useful for (real) parallel processing 1) thread (with GIL) is good for *cpu bound processes* that do not stop the main process while blocked by a system call (the intent is similar to select/poll) 2) for really using multiple cores/cpus use something more appropriated or make Mr. Van Rossum change his mind! :-)
http://mail.python.org/pipermail/python-3000/2007-May/007414.html Object instantiated in python threads are isolated so they live their own life no worry about that Anyway do you like singletons? Python threading has many ways to support that... but read this: http://code.activestate.com/recipes/66531-singleton-we-dont-need-no-stinkin-singleton-the-bo/ wow! :-) 2010/8/24 pierreth <[email protected]>: > On 24 août, 01:20, mdipierro <[email protected]> wrote: >> In Java a serverlet, as far as I understand, is a class which conforms >> to some API that allows it to serve one http request. Each instance is >> executed in its own thread. > > Yes, but one instance can be executed by multiple threads at the same > time. It is one thread per request. EJB, Enterprise Java Beans, are > running on their own threads. > >>The Python equivalent of the serverlet API >> is a WSGI application and web2py is based on WSGI, therefore the >> parallelization mechanism is equivalent to Java serverlets. > > Is web2py running as a WSGI application when we do "python web2py.py" > or is it only when used in a specific deployment with WSGI? > >> >> In web2py (the same in Django, Pylons, any any WSGI app) each http >> request is executed in its own thread. Threads are recycled to server >> non-concurrent requests and reuse database connections (pooling) >> without need to close and reopen them. The web server can be >> configured for a min number and a max number of threads. > > So, as a web2py developer, what do I have to do to avoid > synchronization problems in my application. Where is the danger of > having multiple threads for the web2py developers? What are the > instances shared my multiple threads? What are the instances living in > their own threads? > >> >> I think the GIL in this context is a false problem. In fact in >> production you can use Apache and run as many processes as the number >> of cores that you have. Each process will create as many threads as it >> needs to server multiple requests. The GIL is a problems only if one >> process runs multiple threads on multiple cores. It is possible there >> are some caveats with many cores but I have not really played with >> apache configurations and benchmarks. > > Yes but a web2py server is running with only one process and using > more web2py processes for serving the same web2py app will lead to > synchronization problems. With processors having more and more cores, > having a web server that cannot use them is not very fun. It is an > issue to be solved with Python 3.2 I think. > >> Massimo >> > > Thank you for this precious information.

