Skip to content

Main process

Classes

MainProcess

MainProcess(*args, **kwargs)

OptionsGroup

Main process is the uWSGI process.

Warning

Do not run uWSGI instances as root. You can start your uWSGIs as root, but be sure to drop privileges with the uid and gid options from set_owner_params.


name

.name: str = ''

Name to represent the group.


plugin

.plugin: bool | str = False

Indication this option group belongs to a plugin.


change_dir

1
2
3
4
.change_dir(
    to: Strpath,  # (1)!
    after_app_loading: bool = False,  # (2)!
)
  1. Target directory.

  2. True - after load False - before load

Chdir to specified directory before or after apps loading.


daemonize

1
2
3
4
.daemonize(
    log_into: str, 
    after_app_loading: bool = False,  # (1)!
)
  1. Whether to daemonize after or before applications loading.

Daemonize uWSGI.


get_owner

1
2
3
.get_owner(
    default: bool = True,  # (1)!
) -> tuple[Strint | None, Strint | None]
  1. Whether to return default if not set.

Return (User ID, Group ID) tuple


run_command_on_event

1
2
3
4
.run_command_on_event(
    command: str, 
    phase: str = phases.ASAP,  # (1)!
)
  1. See constants in Phases class.

Run the given command on a given phase.


run_command_on_touch

1
2
3
4
.run_command_on_touch(
    command: str, 
    target: str,  # (1)!
)
  1. File path.

Run command when the specified file is modified/touched.


set_basic_params

1
2
3
4
5
6
7
.set_basic_params(
    touch_reload: Strlist = None,  # (1)!
    priority: int | None = None,  # (2)!
    vacuum: bool | None = None,  # (3)!
    binary_path: str | None = None,  # (4)!
    honour_stdin: bool | None = None,  # (5)!
)
  1. Reload uWSGI if the specified file or directory is modified/touched.

  2. Set processes/threads priority (nice) value.

  3. Try to remove all the generated files/sockets (UNIX sockets and pidfiles) upon exit.

  4. Force uWSGI binary path. If you do not have uWSGI in the system path you can force its path with this option to permit the reloading system and the Emperor to easily find the binary to execute.

  5. Do not remap stdin to /dev/null. By default, stdin is remapped to /dev/null on uWSGI startup. If you need a valid stdin (for debugging, piping and so on) use this option.


set_hook

1
2
3
4
.set_hook(
    phase: str,  # (1)!
    action: TypeActionExt
)
  1. See constants in .phases.

Allows setting hooks (attaching actions) for various uWSGI phases.


set_hook_after_request

.set_hook_after_request(func: str)

Run the specified function/symbol (C level) after each request.


set_hook_touch

1
2
3
4
.set_hook_touch(
    fpath: Strpath,  # (1)!
    action: TypeActionExt
)
  1. File path.

Allows running certain action when the specified file is touched.


set_memory_params

1
2
3
4
.set_memory_params(
    ksm_interval: int | None = None,  # (1)!
    no_swap: bool | None = None,  # (2)!
)
  1. Kernel Samepage Merging frequency option, that can reduce memory usage. Accepts a number of requests (or master process cycles) to run page scanner after.

    Note

    Linux only.

  2. Lock all memory pages avoiding swapping.

Set memory related parameters.


set_naming_params

1
2
3
4
5
6
.set_naming_params(
    autonaming: bool | None = None,  # (1)!
    prefix: str | None = None,  # (2)!
    suffix: str | None = None,  # (3)!
    name: str | None = None,  # (4)!
)
  1. Automatically set process name to something meaningful. Generated process names may be 'uWSGI Master', 'uWSGI Worker #', etc.

  2. Add prefix to process names.

  3. Append string to process names.

  4. Set process names to given static value.

Setups processes naming parameters.


set_on_exit_params

1
2
3
4
.set_on_exit_params(
    skip_hooks: bool | None = None,  # (1)!
    skip_teardown: bool | None = None,  # (2)!
)
  1. Skip EXIT phase hook.

    1
    .. note:: Ignored by the master.
    
  2. Allows skipping teardown (finalization) processes for some plugins.

    1
    2
    3
    4
    5
    .. note:: Ignored by the master.
    
    Supported by:
        * Perl
        * Python
    

Set params related to process exit procedure.


set_owner_params

1
2
3
4
5
6
7
.set_owner_params(
    uid: Strint = None,  # (1)!
    gid: Strint = None,  # (2)!
    add_gids: Strint | list[Strint] = None,  # (3)!
    set_asap: bool = False,  # (4)!
    drop_after: str = '',  # (5)!
)
  1. Set uid to the specified username or uid.

  2. Set gid to the specified groupname or gid.

  3. Add the specified group id to the process credentials. This options allows you to add additional group ids to the current process. You can specify it multiple times.

  4. Set as soon as possible. Setting them on top of your vassal file will force the instance to setuid()/setgid() as soon as possible and without the (theoretical) possibility to override them.

  5. When to drop privileges (e.g. if initially run as root):

    • 'init' - drop after plugin initialization
    • 'apps' - drop after apps loading

Set process owner params - user, group.


set_pid_file

1
2
3
4
5
.set_pid_file(
    fpath: Strpath,  # (1)!
    before_priv_drop: bool = True,  # (2)!
    safe: bool = False,  # (3)!
)
  1. File path.

  2. Whether to create pidfile before privileges are dropped.

    1
    2
    .. note:: Vacuum is made after privileges drop, so it may not be able
        to delete PID file if it was created before dropping.
    
  3. The safe-pidfile works similar to pidfile but performs write a little later in the loading process. This avoids overwriting the value when app loading fails, with the consequent loss of a valid PID number.

Creates pidfile before or after privileges drop.


actions

.actions()

Actions available for .set_hook().


phases

.phases()

Phases available for hooking using .set_hook().

Some of them may be fatal - a failing hook for them will mean failing of the whole uWSGI instance (generally calling exit(1)).


APP_LOAD_POST
.APP_LOAD_POST = 'post-app'

After app loading. Fatal


APP_LOAD_PRE
.APP_LOAD_PRE = 'pre-app'

Before app loading. Fatal


ASAP
.ASAP = 'asap'

As soon as possible. Fatal

Run directly after configuration file has been parsed, before anything else is done.


EMPEROR_LOST
.EMPEROR_LOST = 'emperor-lost'

When Emperor connection is lost.


EMPEROR_RELOAD
.EMPEROR_RELOAD = 'emperor-reload'

When Emperor sent a reload message.


EMPEROR_START
.EMPEROR_START = 'emperor-start'

When Emperor starts.


EMPEROR_STOP
.EMPEROR_STOP = 'emperor-stop'

When Emperor sent a stop message.


EXIT
.EXIT = 'as-user-atexit'

Before app exit and reload.


GATEWAY_START_IN_EACH
.GATEWAY_START_IN_EACH = 'as-gateway'

In each gateway on start.


JAIL_IN
.JAIL_IN = 'in-jail'

In jail after initialization. Fatal

Run soon after jayling, but after post-jail. If jailing requires fork(), the chidlren run this phase.


JAIL_POST
.JAIL_POST = 'post-jail'

After jailing. Fatal

Run soon after any jailing, but before privileges drop. If jailing requires fork(), the parent process run this phase.


JAIL_PRE
.JAIL_PRE = 'pre-jail'

Before jailing. Fatal

Run before any attempt to drop privileges or put the process in some form of jail.


MASTER_START
.MASTER_START = 'master-start'

When Master starts.


MULE_START_IN_EACH
.MULE_START_IN_EACH = 'as-mule'

In each mule on start.


PRIV_DROP_POST
.PRIV_DROP_POST = 'as-user'

After privileges drop. Fatal


PRIV_DROP_PRE
.PRIV_DROP_PRE = 'as-root'

Before privileges drop. Fatal

Last chance to run something as root.


VASSAL_CONFIG_CHANGE_POST
.VASSAL_CONFIG_CHANGE_POST = 'as-on-config-vassal'

Whenever the emperor detects a config change for an on-demand vassal.


VASSAL_ON_DEMAND_IN
.VASSAL_ON_DEMAND_IN = 'as-on-demand-vassal'

Whenever a vassal enters on-demand mode.


VASSAL_PRIV_DRP_PRE
.VASSAL_PRIV_DRP_PRE = 'as-vassal-before-drop'

In vassal, before dropping its privileges.


VASSAL_SET_NAMESPACE
.VASSAL_SET_NAMESPACE = 'as-emperor-setns'

In the emperor entering vassal namespace.


VASSAL_START_IN
.VASSAL_START_IN = 'as-vassal'

In the vassal before executing the uwsgi binary. Fatal

In vassal on start just before calling exec() directly in the new namespace.


VASSAL_START_POST
.VASSAL_START_POST = 'as-emperor'

In the emperor soon after a vassal has been spawn.

Setting 4 env vars: * UWSGI_VASSAL_CONFIG * UWSGI_VASSAL_PID * UWSGI_VASSAL_UID * UWSGI_VASSAL_GID


VASSAL_START_PRE
.VASSAL_START_PRE = 'as-emperor-before-vassal'

Before the new vassal is spawned.


WORKER_ACCEPTING_PRE_EACH
.WORKER_ACCEPTING_PRE_EACH = 'accepting'

Before the each worker starts accepting requests.

Note

Since 1.9.21


WORKER_ACCEPTING_PRE_EACH_ONCE
.WORKER_ACCEPTING_PRE_EACH_ONCE = 'accepting-once'

Before the each worker starts accepting requests, one time per instance.

Note

Since 1.9.21


WORKER_ACCEPTING_PRE_FIRST
.WORKER_ACCEPTING_PRE_FIRST = 'accepting1'

Before the first worker starts accepting requests.

Note

Since 1.9.21


WORKER_ACCEPTING_PRE_FIRST_ONCE
.WORKER_ACCEPTING_PRE_FIRST_ONCE = 'accepting1-once'

Before the first worker starts accepting requests, one time per instance.

Note

Since 1.9.21