Skip to content

Instantly share code, notes, and snippets.

@ipmb ipmb/
Created May 13, 2018

What would you like to do?
uwsgi as lib
# UWSGI_AS_LIB=`pwd`/saltdash/ pip install uwgi
# via
import sys
import os
import ctypes
from importlib import resources
except ImportError:
import importlib_resources as resources
def uwsgi_run(uwsgi_binary, uwsgi_args):
# load the uwsgi library in the global namespace
with resources.path('saltdash', '') as libuwsgi:
uwsgi = ctypes.CDLL(str(libuwsgi), mode=ctypes.RTLD_GLOBAL)
args = [
'--binary-path', uwsgi_binary,
'--module', 'saltdash.wsgi',
uwsgi_args = uwsgi_args or [
'--workers', str(os.cpu_count() or 2),
'--http', '',
'--procname-prefix-spaced', 'saltdash:',
# build command line args
argv = (ctypes.c_char_p * (len(args) + 1))()
for pos, arg in enumerate(args):
argv[pos] = bytes(arg, 'utf-8')
# 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(args), argv, envs)
if __name__ == '__main__':
uwsgi_run(sys.argv[0], sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.