Python¶
-
class
uwsgiconf.options.python.
Python
(*args, **kwargs)¶ Python plugin options.
Note
By default the plugin does not initialize the GIL. This means your app-generated threads will not run. If you need threads, remember to enable them with
enable_threads
.-
set_basic_params
(*, version: Union[str, int] = -1, python_home: str = None, enable_threads: bool = None, search_path: str = None, python_binary: str = None, tracebacker_path: str = None, plugin_dir: str = None, os_env_reload: bool = None, optimization_level: int = None)¶ Parameters: - version –
Python version plugin supports.
- Example:
- 3 - version 3
- <empty> - version 2
- <default> - version deduced by uwsgiconf
- python_home – Set python executable directory - PYTHONHOME/virtualenv.
- enable_threads (bool) –
Enable threads in the embedded languages. This will allow to spawn threads in your app.
Warning
Threads will simply not work if this option is not enabled. There will likely be no error, just no execution of your thread code.
- search_path –
Add directory (or an .egg or a glob) to the Python search path.
Note
This can be specified up to 64 times.
- python_binary – Set python program name.
- tracebacker_path – Enable the uWSGI Python tracebacker. http://uwsgi-docs.readthedocs.io/en/latest/Tracebacker.html
- plugin_dir – Directory to search for plugin.
- os_env_reload – Force
os.environ
reloading for every request. Used to allow setting ofUWSGI_SETENV
for Python applications. - optimization_level – Python optimization level (see
-O
argument). .. warning:: This may be dangerous for some apps.
- version –
-
set_app_args
(*args)¶ Sets
sys.argv
for python apps.- Examples:
- pyargv=”one two three” will set
sys.argv
to('one', 'two', 'three')
.
- pyargv=”one two three” will set
Parameters: args –
-
set_wsgi_params
(*, module: Union[str, pathlib.Path] = None, callable_name: str = None, env_strategy: str = None)¶ Set wsgi related parameters.
Parameters: - module –
- load .wsgi file as the Python application
- load a WSGI module as the application.
Note
The module (sans
.py
) must be importable, ie. be inPYTHONPATH
.- Examples:
- mypackage.my_wsgi_module – read from application attr of mypackage/my_wsgi_module.py
- mypackage.my_wsgi_module:my_app – read from my_app attr of mypackage/my_wsgi_module.py
- callable_name – Set WSGI callable name. Default: application.
- env_strategy –
Strategy for allocating/deallocating the WSGI env, can be:
cheat
- preallocates the env dictionary on uWSGI startup and clears it- after each request. Default behaviour for uWSGI <= 2.0.x
holy
- creates and destroys the environ dictionary at each request.- Default behaviour for uWSGI >= 2.1
- module –
-
eval_wsgi_entrypoint
(code: str)¶ Evaluates Python code as WSGI entry point.
Parameters: code –
-
set_autoreload_params
(*, scan_interval: int = None, ignore_modules: Union[str, List[str]] = None)¶ Sets autoreload related parameters.
Parameters: - scan_interval –
Seconds. Monitor Python modules’ modification times to trigger reload.
Warning
Use only in development.
- ignore_modules – Ignore the specified module during auto-reload scan.
- scan_interval –
-
register_module_alias
(alias: str, module_path: str, *, after_init: bool = False)¶ Adds an alias for a module.
http://uwsgi-docs.readthedocs.io/en/latest/PythonModuleAlias.html
Parameters: - alias –
- module_path –
- after_init – add a python module alias after uwsgi module initialization
-
import_module
(modules: Union[str, int], *, shared: bool = False, into_spooler: bool = False)¶ Imports a python module.
Parameters: - modules –
- shared – If shared import is done once in master process. Otherwise import a python module in all of the processes. This is done after fork but before request processing.
- into_spooler – Import a python module in the spooler. http://uwsgi-docs.readthedocs.io/en/latest/Spooler.html
-
run_module
(module: str)¶ Runs a Python script in the uWSGI environment.
Parameters: module –
-