Master process

class uwsgiconf.options.master_process.MasterProcess(*args, **kwargs)

Master process is a separate process offering mentoring capabilities for other processes. Only one master process per uWSGI instance.

uWSGI’s built-in prefork+threading multi-worker management mode, activated by flicking the master switch on.

Note

For all practical serving deployments it’s not really a good idea not to use master mode.

set_basic_params(enable=None, name=None, no_orphans=None, as_root=None, subproc_check_interval=None, fifo_file=None)
Parameters:
  • enable (bool) – Enable uWSGI master process.
  • master_enabled (str|unicode) – Set master process name to given value.
  • no_orphans (bool) – Automatically kill workers if master dies (can be dangerous for availability).
  • as_root (bool) – Leave master process running as root.
  • subproc_check_interval (int) –

    Set the interval (in seconds) of master checks. Default: 1 The master process makes a scan of subprocesses, etc. every N seconds.

    Warning

    You can increase this time if you need to, but it’s DISCOURAGED.

  • fifo_file (str|unicode) –

    Enables the master FIFO.

    Note

    Placeholders can be used to build paths, e.g.: {project_runtime_dir}.fifo See Section.project_name and Section.runtime_dir.

    Instead of signals, you can tell the master to create a UNIX named pipe (FIFO) that you may use to issue commands to the master.

    Up to 10 different FIFO files supported. By default the first specified is bound (mapped as ‘0’).

    Note

    Since 1.9.17

set_exit_events(no_workers=None, idle=None, reload=None, sig_term=None)

Do exit on certain events

Parameters:
  • no_workers (bool) – Shutdown uWSGI when no workers are running.
  • idle (bool) – Shutdown uWSGI when idle.
  • reload (bool) – Force exit even if a reload is requested.
  • sig_term (bool) –

    Exit on SIGTERM instead of brutal workers reload.

    Note

    Before 2.1 SIGTERM reloaded the stack while SIGINT/SIGQUIT shut it down.

set_exception_handling_params(handler=None, catch=None, no_write_exception=None)

Exception handling related params.

Parameters:
  • handler (str|unicode|list[str|unicode]) – Register one or more exception handling C-functions.
  • catch (bool) –

    Catch exceptions and report them as http output (including stack trace and env params).

    Warning

    Use only for testing purposes.

  • no_write_exception (bool) –

    Disable exception generation on write()/writev().

    Note

    This can be combined with logging.set_filters(write_errors=False, sigpipe=False).

set_idle_params(timeout=None, exit=None)

Activate idle mode - put uWSGI in cheap mode after inactivity timeout.

Parameters:
  • timeout (int) – Inactivity timeout in seconds.
  • exit (bool) – Shutdown uWSGI when idle.
set_reload_params(mercy=None, exit=None)

Set reload related params.

Parameters:
  • mercy (int) – Set the maximum time (in seconds) we wait for workers and other processes to die during reload/shutdown.
  • exit (bool) – Force exit even if a reload is requested.
add_cron_task(command, weekday=None, month=None, day=None, hour=None, minute=None, legion=None, unique=None, harakiri=None)

Adds a cron task running the given command on the given schedule. http://uwsgi.readthedocs.io/en/latest/Cron.html

HINTS:
  • Use negative values to say every:
    hour=-3 stands for every 3 hours
  • Use - (minus) to make interval:
    minute=‘13-18’ stands for from minute 13 to 18

Note

We use cron2 option available since 1.9.11.

Parameters:
  • command (str|unicode) – Command to execute on schedule (with or without path).
  • weekday (int|str|unicode) – Day of a the week number. Defaults to each. 0 - Sunday 1 - Monday 2 - Tuesday 3 - Wednesday 4 - Thursday 5 - Friday 6 - Saturday
  • month (int|str|unicode) – Month number 1-12. Defaults to each.
  • day (int|str|unicode) – Day of the month number 1-31. Defaults to each.
  • hour (int|str|unicode) – Hour 0-23. Defaults to each.
  • minute (int|str|unicode) – Minute 0-59. Defaults to each.
  • legion (str|unicode) – Set legion (cluster) name to use this cron command against. Such commands are only executed by legion lord node.
  • unique (bool) – Marks command as unique. Default to not unique. Some commands can take a long time to finish or just hang doing their thing. Sometimes this is okay, but there are also cases when running multiple instances of the same command can be dangerous.
  • harakiri (int) – Enforce a time limit (in seconds) on executed commands. If a command is taking longer it will be killed.
attach_process_classic(command_or_pid_path, background, control=False, for_legion=False)

Attaches a command/daemon to the master process optionally managed by a pidfile.

This will allow the uWSGI master to control/monitor/respawn this process.

Note

This uses old classic uWSGI means of process attaching To have more control use .attach_process() method (requires uWSGI 2.0+)

http://uwsgi-docs.readthedocs.io/en/latest/AttachingDaemons.html

Parameters:
  • command_or_pid_path (str|unicode) –
  • background (bool) – Must indicate whether process is in background.
  • control (bool) –

    Consider this process a control: when the daemon dies, the master exits.

    Note

    pidfile managed processed not supported.

  • for_legion (bool) –

    Legion daemons will be executed only on the legion lord node, so there will always be a single daemon instance running in each legion. Once the lord dies a daemon will be spawned on another node.

    Note

    uWSGI 1.9.9+ required.

attach_process(command, for_legion=False, broken_counter=None, pidfile=None, control=None, daemonize=None, touch_reload=None, signal_stop=None, signal_reload=None, honour_stdin=None, uid=None, gid=None, new_pid_ns=None, change_dir=None)

Attaches a command/daemon to the master process.

This will allow the uWSGI master to control/monitor/respawn this process.

http://uwsgi-docs.readthedocs.io/en/latest/AttachingDaemons.html

Parameters:
  • command (str|unicode) – The command line to execute.
  • for_legion (bool) – Legion daemons will be executed only on the legion lord node, so there will always be a single daemon instance running in each legion. Once the lord dies a daemon will be spawned on another node.
  • broken_counter (int) – Maximum attempts before considering a daemon “broken”.
  • pidfile (str|unicode) – The pidfile path to check (enable smart mode).
  • control (bool) – If True, the daemon becomes a control one: if it dies the whole uWSGI instance dies.
  • daemonize (bool) – Daemonize the process (enable smart2 mode).
  • touch_reload (list|str|unicode) – List of files to check: whenever they are ‘touched’, the daemon is restarted
  • signal_stop (int) – The signal number to send to the daemon when uWSGI is stopped.
  • signal_reload (int) – The signal number to send to the daemon when uWSGI is reloaded.
  • honour_stdin (bool) – The signal number to send to the daemon when uWSGI is reloaded.
  • uid (str|unicode|int) –

    Drop privileges to the specified uid.

    Note

    Requires master running as root.

  • gid (str|unicode|int) –

    Drop privileges to the specified gid.

    Note

    Requires master running as root.

  • new_pid_ns (bool) –

    Spawn the process in a new pid namespace.

    Note

    Requires master running as root.

    Note

    Linux only.

  • change_dir (str|unicode) – Use chdir() to the specified directory before running the command.