Main process

class uwsgiconf.options.main_process.MainProcess(*args, **kwargs)

Main process is the uWSGI process.


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.

class actions

Actions available for .set_hook().


alias of uwsgiconf.options.main_process_actions.ActionAlarm


alias of uwsgiconf.options.main_process_actions.ActionCall


alias of uwsgiconf.options.main_process_actions.ActionDirChange


alias of uwsgiconf.options.main_process_actions.ActionDirCreate


alias of uwsgiconf.options.main_process_actions.ActionExecute


alias of uwsgiconf.options.main_process_actions.ActionExit


alias of uwsgiconf.options.main_process_actions.ActionFifoWrite


alias of uwsgiconf.options.main_process_actions.ActionFileCreate


alias of uwsgiconf.options.main_process_actions.ActionFileWrite


alias of uwsgiconf.options.main_process_actions.ActionMount


alias of uwsgiconf.options.main_process_actions.ActionPrintout


alias of uwsgiconf.options.main_process_actions.ActionSetHostName

alias of uwsgiconf.options.main_process_actions.ActionUnlink

class 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)).

ASAP = 'asap'

As soon as possible. Fatal

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

JAIL_PRE = 'pre-jail'

Before jailing. Fatal

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

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 = 'post-jail'

After jailing. Fatal

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

PRIV_DROP_PRE = 'as-root'

Before privileges drop. Fatal

Last chance to run something as root.

PRIV_DROP_POST = 'as-user'

After privileges drop. Fatal

MASTER_START = 'master-start'

When Master starts.

EMPEROR_START = 'emperor-start'

When Emperor starts.

EMPEROR_STOP = 'emperor-stop'

When Emperor sent a stop message.

EMPEROR_RELOAD = 'emperor-reload'

When Emperor sent a reload message.

EMPEROR_LOST = 'emperor-lost'

When Emperor connection is lost.

EXIT = 'as-user-atexit'

Before app exit and reload.

APP_LOAD_PRE = 'pre-app'

Before app loading. Fatal

APP_LOAD_POST = 'post-app'

After app loading. Fatal

VASSAL_ON_DEMAND_IN = 'as-on-demand-vassal'

Whenever a vassal enters on-demand mode.

VASSAL_CONFIG_CHANGE_POST = 'as-on-config-vassal'

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

VASSAL_START_PRE = 'as-emperor-before-vassal'

Before the new vassal is spawned.

VASSAL_PRIV_DRP_PRE = 'as-vassal-before-drop'

In vassal, before dropping its privileges.

VASSAL_SET_NAMESPACE = 'as-emperor-setns'

In the emperor entering vassal namespace.

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 = 'as-emperor'

In the emperor soon after a vassal has been spawn.

Setting 4 env vars:
GATEWAY_START_IN_EACH = 'as-gateway'

In each gateway on start.

MULE_START_IN_EACH = 'as-mule'

In each mule on start.


Before the each worker starts accepting requests.


Since 1.9.21


Before the first worker starts accepting requests.


Since 1.9.21


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


Since 1.9.21


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


Since 1.9.21

set_basic_params(*, touch_reload: Union[str, List[str]] = None, priority: int = None, vacuum: bool = None, binary_path: str = None, honour_stdin: bool = None)
  • touch_reload – Reload uWSGI if the specified file or directory is modified/touched.
  • priority – Set processes/threads priority (nice) value.
  • vacuum – Try to remove all of the generated files/sockets (UNIX sockets and pidfiles) upon exit.
  • binary_path – 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.
  • honour_stdin – 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_memory_params(*, ksm_interval: int = None, no_swap: bool = None)

Set memory related parameters.

  • ksm_interval

    Kernel Samepage Merging frequency option, that can reduce memory usage. Accepts a number of requests (or master process cycles) to run page scanner after.


    Linux only.

  • no_swap – Lock all memory pages avoiding swapping.
daemonize(log_into: str, *, after_app_loading: bool = False)

Daemonize uWSGI.

  • log_into (str) –

    Logging destination:

    • File: /tmp/mylog.log
    • UPD:


      This will require an UDP server to manage log messages. Use networking.register_socket(', type=networking.SOCK_UDP) to start uWSGI UDP server.

  • after_app_loading – Whether to daemonize after or before applications loading.
change_dir(to: str, *, after_app_loading: bool = False)

Chdir to specified directory before or after apps loading.

  • to – Target directory.
  • after_app_loadingTrue - after load False - before load
set_owner_params(*, uid: Union[str, int] = None, gid: Union[str, int] = None, add_gids: Union[str, int, List[Union[str, int]]] = None, set_asap: bool = False)

Set process owner params - user, group.

  • uid – Set uid to the specified username or uid.
  • gid – Set gid to the specified groupname or gid.
  • add_gids – 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.
  • set_asap – 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.
get_owner(*, default: bool = True) → Tuple[Union[str, int, None], Union[str, int, None]]

Return (User ID, Group ID) tuple

Parameters:default – Whether to return default if not set.
set_hook(phase: str, action: Union[str, HookAction, List[Union[str, HookAction]]])

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

  • phase – See constants in .phases.
  • action
set_hook_touch(fpath: Union[str, pathlib.Path], action: Union[str, HookAction, List[Union[str, HookAction]]])

Allows running certain action when the specified file is touched.

  • fpath – File path.
  • action
set_hook_after_request(func: str)

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

set_on_exit_params(*, skip_hooks: bool = None, skip_teardown: bool = None)

Set params related to process exit procedure.

  • skip_hooks

    Skip EXIT phase hook.


    Ignored by the master.

  • skip_teardown

    Allows skipping teardown (finalization) processes for some plugins.


    Ignored by the master.

    Supported by:
    • Perl
    • Python
run_command_on_event(command: str, *, phase: str = 'asap')

Run the given command on a given phase.

  • command
  • phase – See constants in Phases class.
run_command_on_touch(command: str, *, target: str)

Run command when the specified file is modified/touched.

  • command
  • target – File path.
set_pid_file(fpath: Union[str, pathlib.Path], *, before_priv_drop: bool = True, safe: bool = False)

Creates pidfile before or after privileges drop.

  • fpath – File path.
  • before_priv_drop

    Whether to create pidfile before privileges are dropped.


    Vacuum is made after privileges drop, so it may not be able to delete PID file if it was created before dropping.

  • safe – The safe-pidfile works similar to pidfile but performs the 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.
set_naming_params(*, autonaming: bool = None, prefix: str = None, suffix: str = None, name: str = None)

Setups processes naming parameters.

  • autonaming – Automatically set process name to something meaningful. Generated process names may be ‘uWSGI Master’, ‘uWSGI Worker #’, etc.
  • prefix – Add prefix to process names.
  • suffix – Append string to process names.
  • name – Set process names to given static value.