Do Python webapps require prefork Apache?

Python has a concept known as Global Interpreter Lock (GIL). It means that one Python interpreter process only runs one thread at a time. That's it.

Naturally, webapps tend to use multiple threads to serve multiple requests concurrently (especially if a single request takes some time).

So far, the only Python webapps I've seen used Gunicorn, which uses the old "1 master process, N worker process" prefork approach.

I know Apache supports Python via mod_python and mod_wsgi. Does this mean that Apache+Python requires using the prefork MPM approach?

7 comments · 63% upvoted · other discussions

comments

IOI-65536

In case somebody sees this and cares, that's a sometimes important oversimplification of the GIL. Only one thread can be interpreting Python bytecode at a time. You can absolutely have two threads doing I/O (and a bunch of other things where a single python instruction takes a long time) simultaneously.

youngeng [OP]

Interesting, thanks.

gordonmessmer

mod_wsgi is the recommended platform for python apps, and it has documentation that discusses worker / prefork:

https://modwsgi.readthedocs.io/en/latest/user-guides/processes-and-threading.html

AdrianTeri

Apache+Python

Why adamant on Apache's HTTPD?

https://docs.gunicorn.org/en/latest/deploy.html

youngeng [OP]

I know very well Gunicorn+Python works, as I've said in the post. This doesn't mean I don't want to explore how it works with Apache.

AdrianTeri

You then know Apache's limitations(similar family to buffered IO problems) and that inspired creation Nginx.