4 ms·
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? Optional
by ptx 5y ago
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.
- mayli 5y agoFork 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.
- dfox 5y agoThe whole PHP opcache hack works reliably only on platforms that have fork(2).
- ptx 5y agoWell, 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 https://uwsgi-docs.readthedocs.io/en/latest/ForkServer.html [2] https://uwsgi-docs.readthedocs.io/en/latest/Options.html#max-requests https://uwsgi-docs.readthedocs.io/en/latest/Options.html#max...
- duskwuff 5y agoIn 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.