Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config from plugins (eg. python:// for statically link python) #564

Open
anthonyrisinger opened this issue Mar 14, 2014 · 2 comments
Open

Comments

@anthonyrisinger
Copy link
Contributor

i think it would be REALLY useful to activate plugins as a config source, specifically:

--json python://package.module:callable()

...would use import package.module; return package.module.callable() as JSON config, whereas:

--ini python://package.module:object

...would use import package.module; return package.module.object as INI config (note: this mirrors the --module, --callable, and --mount syntax)

this would allow me to move our entire config to python (with access to uwsgi.opt hopefully!)... combined with a writable uwsgi.opt (that future config can see!) i'd be ecstatic!

@unbit
Copy link
Owner

unbit commented Mar 15, 2014

There are lot of implications in this, as it would means initializing languages vm before the user has configured the environment and so on. There are really a lot of corner cases for it. What about this trick:

UWSGI_AS_LIB=libuwsgi.so make
#!/usr/bin/python

import sys
import ctypes

def application(e, sr):
    sr('200 OK',[('Content-Type','text/html')])
    return ["Hello World"]

def uwsgi_run(uwsgi_args):
    # load the uwsgi library in the global namespace
    uwsgi = ctypes.CDLL('./libuwsgi.so',mode=ctypes.RTLD_GLOBAL)

    uwsgi_args.insert(0, sys.argv[0])
    uwsgi_args.insert(1, '--binary-path')
    uwsgi_args.insert(2, sys.argv[0])

    # build command line args
    argv = (ctypes.c_char_p * (len(uwsgi_args)+1))()
    for pos,arg in enumerate(uwsgi_args):
        argv[pos] = arg
    # inform the uwsgi engine, the passed environ is not safe to overwrite
    envs = (ctypes.c_char_p * 1)()
    # enter into uWSGI !!!
    uwsgi.uwsgi_init(len(uwsgi_args), argv, envs)

if __name__ == "__main__":
    uwsgi_run(['--http-socket', ':9090', '--master', '--processes', '8', '--wsgi-file', sys.argv[0]])
./u.py

you need to use latest code from github as it ensure python is not re-initialized if a vm is already available

@unbit
Copy link
Owner

unbit commented Mar 15, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants