Skip to content

Commit

Permalink
Introduced Applications options group.
Browse files Browse the repository at this point in the history
  • Loading branch information
idlesign committed Jul 5, 2017
1 parent 791e981 commit 10ca6dc
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 3 deletions.
6 changes: 6 additions & 0 deletions docs/source/grp_applications.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Applications
============

.. automodule:: uwsgiconf.options.applications
:members:

1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ API
:maxdepth: 3

config
grp_applications
grp_locks
grp_main_process
grp_master_process
Expand Down
7 changes: 4 additions & 3 deletions uwsgiconf/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ class Section(SectionBase):
)
"""
grp_applications = Options(Applications) # type: Applications
grp_locks = Options(Locks) # type: Locks
grp_main_process = Options(MainProcess) # type: MainProcess
grp_master_process = Options(MasterProcess) # type: MasterProcess
grp_networking = Options(Networking) # type: Networking
grp_workers = Options(Workers) # type: Workers
grp_master_process = Options(MasterProcess) # type: MasterProcess
grp_main_process = Options(MainProcess) # type: MainProcess
grp_locks = Options(Locks) # type: Locks

grp_plugin_python = Options(PythonPlugin) # type: PythonPlugin

Expand Down
1 change: 1 addition & 0 deletions uwsgiconf/options/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .applications import Applications
from .locks import Locks
from .main_process import MainProcess
from .master_process import MasterProcess
Expand Down
96 changes: 96 additions & 0 deletions uwsgiconf/options/applications.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
from ..base import OptionsGroup


class Applications(OptionsGroup):
"""Applications.
"""

def set_basic_params(
self, exit_if_none=None, max_per_worker=None, single_interpreter=None, no_default=None):
"""
:param bool exit_if_none: Exit if no app can be loaded.
:param int max_per_worker: Set the maximum number of per-worker applications.
:param bool single_interpreter: Do not use multiple interpreters (where available).
Some of the supported languages (such as Python) have the concept of "multiple interpreters".
By default every app is loaded in a new python interpreter (that means a pretty-well isolated
namespace for each app). If you want all of the app to be loaded in the same python vm,
use the this option.
:param bool no_default: Do not fallback to default app.
"""

self._set('need-app', exit_if_none, cast=bool)
self._set('max-apps', max_per_worker)
self._set('single-interpreter', single_interpreter, cast=bool)
self._set('no-default-app', no_default, cast=bool)

return self._section

def change_dir(self, to, after_load=False):
"""Chdir to specified directory before or after apps loading.
:param str|unicode to: Target directory.
:param bool after_load:
*True* - after load
*False* - before load
"""
self._set('chdir2' if after_load else 'chdir', to)

return self._section

def mount(self, mountpoint, app, into_worker=False):
"""Load application under mountpoint.
Example:
* .mount('/app1', 'app1.py')
* .mount('example.com', 'app2.py')
* .mount('the_app3', 'app3.py')
* .mount('/pinax', '/var/www/pinax/deploy/pinax.wsgi')
http://uwsgi-docs.readthedocs.io/en/latest/Nginx.html?highlight=mount#hosting-multiple-apps-in-the-same-process-aka-managing-script-name-and-path-info
:param str|unicode mountpoint:
:param str|unicode app:
"""
self._set('mount', '%s=%s' % (mountpoint, app), cast=bool)

return self._section

def set_idle_params(self, timeout=None, exit=None):
"""
:param int timeout: Activate idle mode - put uWSGI in cheap mode
after inactivity timeout.
:param bool exit: Shutdown uWSGI when idle.
"""
self._set('idle', timeout)
self._set('die-on-idle', exit, cast=bool)

return self._section

def set_lazy_mode(self, affect_master=None):
"""Load apps in workers instead of master.
This option may have memory usage implications
as Copy-on-Write semantics can not be used.
:param bool affect_master: If **True** only workers will be
reloaded by uWSGI's reload signals; the master will remain alive.
.. warning:: uWSGI configuration changes are not picked up on reload by the master.
"""
self._set('lazy' if affect_master else 'lazy-apps', True, cast=bool)

return self._section

0 comments on commit 10ca6dc

Please sign in to comment.