unbit/uwsgi — pull request #282 by xtfxme (2013-05-14 21:03:58+00:00)
Title: [rfc] Py_Main: 100% python with access to uwsgi API (ln -s uwsgi python; ./python)

if `basename argv[0]` starts with `python`, run Python directly, after exposing the embedded module. at it's core this is `--pyshell` with the bits needed to replace the python binary itself.

implemented via the following:

- save `uwsgi.argc` to `up.pymain`
- set `uwsgi.argc = 1`, effectively preventing uWSGI from looking at cmdline args (note: embedded config can still be used... this is a feature/solution to CLI parsing problem!)
- save `sigaction(SIGINT, NULL, up.pymain_intr)` immediately after `Py_Initialize()`
- restore `sigaction(SIGINT, up.pymain_intr, NULL)` and call `Py_Main()`

i have another version here: https://github.com/xtfxme/uwsgi/compare/rfc;Py_Main-VAL

...that makes a copy of `uwsgi.argv`, but i dont see the point, and it's more complex.

looking for comments on how this can be best integrated into uWSGI proper; it actually turned out much cleaner than i expected, but there are certainly some bits that could be smooothed out (in particular, then need to [re]store the sig handler). if need be, it can probably be implemented as a separate plugin (or perhaps a way to opt-out).

i think people would like this quite a bit -- for static python builds it means you dont have 2 copies of the same thing (`python.c` is literally a single line of code: `exit(Py_Main(...))`)