Hacker News new | past | comments | ask | show | jobs | submit login

To do this in Python, couldn't you just fork the Python process after initializing the web framework etc. and handle the request in the forked process? Optionally keep a pool of pre-forked worker processes so that the request doesn't have to wait for the forking. Sort of like Android's zygote process.



In principle, yes. But forking an application server gets tricky -- some resources (like database connections) aren't fork-safe, and need to be recreated after forking.


Fork is kind of expensive in most OS, even it's relative cheap compared to start a new process from scratch, but still much slower than few function calls.


Well, yes, but the point was to get a process per request just like PHP, so you'll have to start those processes one way or another.

Anyway, it appears uwsgi can be configured to do this, using fork-server[1] and maybe max-requests[2], although it only works with Perl at the moment.

[1] https://uwsgi-docs.readthedocs.io/en/latest/ForkServer.html

[2] https://uwsgi-docs.readthedocs.io/en/latest/Options.html#max...


The whole PHP opcache hack works reliably only on platforms that have fork(2).




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: