arbiter

Module Contents

Classes

Arbiter(self,app) Arbiter maintain the workers processes alive. It launches or
class Arbiter(app)

Arbiter maintain the workers processes alive. It launches or kills them if needed. It also manages application reloading via SIGHUP/USR2.

__init__(app)
_get_num_workers()
_set_num_workers(value)
setup(app)
start()

Initialize the arbiter. Start listening and set pidfile if needed.

init_signals()

Initialize master signal handling. Most of the signals are queued. Child signals only wake up the master.

signal(sig, frame)
run()

“Main master loop.”

handle_chld(sig, frame)

“SIGCHLD handling”

handle_hup()

HUP handling. - Reload configuration - Start the new worker processes with a new configuration - Gracefully shutdown the old worker processes

handle_term()

“SIGTERM handling”

handle_int()

“SIGINT handling”

handle_quit()

“SIGQUIT handling”

handle_ttin()

SIGTTIN handling. Increases the number of workers by one.

handle_ttou()

SIGTTOU handling. Decreases the number of workers by one.

handle_usr1()

SIGUSR1 handling. Kill all workers by sending them a SIGUSR1

handle_usr2()

SIGUSR2 handling. Creates a new master/worker set as a slave of the current master without affecting old workers. Use this to do live deployment with the ability to backout a change.

handle_winch()

SIGWINCH handling

maybe_promote_master()
wakeup()

Wake up the arbiter by writing to the PIPE

halt(reason=None, exit_status=0)

halt arbiter

sleep()

Sleep until PIPE is readable or we timeout. A readable PIPE means a signal occurred.

stop(graceful=True)

Stop workers

Attr graceful:boolean, If True (the default) workers will be

killed gracefully (ie. trying to wait for the current connection)

reexec()

Relaunch the master and workers.

reload()
murder_workers()

Kill unused/idle workers

reap_workers()

Reap workers to avoid zombie processes

manage_workers()

Maintain the number of workers by spawning or killing as required.

spawn_worker()
spawn_workers()

Spawn new workers as needed.

This is where a worker process leaves the main loop of the master process.

kill_workers(sig)

Kill all workers with the signal sig :attr sig: signal.SIG* value

kill_worker(pid, sig)

Kill a worker

Attr pid:int, worker pid
Attr sig:signal.SIG* value