Arbiter maintain the workers processes alive. It launches or kills them if needed. It also manages application reloading via SIGHUP/USR2.
| 21 | |
| 22 | |
| 23 | class Arbiter: |
| 24 | """ |
| 25 | Arbiter maintain the workers processes alive. It launches or |
| 26 | kills them if needed. It also manages application reloading |
| 27 | via SIGHUP/USR2. |
| 28 | """ |
| 29 | |
| 30 | # A flag indicating if a worker failed to |
| 31 | # to boot. If a worker process exist with |
| 32 | # this error code, the arbiter will terminate. |
| 33 | WORKER_BOOT_ERROR = 3 |
| 34 | |
| 35 | # A flag indicating if an application failed to be loaded |
| 36 | APP_LOAD_ERROR = 4 |
| 37 | |
| 38 | START_CTX = {} |
| 39 | |
| 40 | LISTENERS = [] |
| 41 | WORKERS = {} |
| 42 | |
| 43 | # Sentinel value for non-signal wakeups |
| 44 | WAKEUP_REQUEST = signal.NSIG |
| 45 | |
| 46 | SIGNALS = [getattr(signal, "SIG%s" % x) |
| 47 | for x in "HUP QUIT INT TERM TTIN TTOU USR1 USR2 WINCH".split()] |
| 48 | SIG_NAMES = dict( |
| 49 | (getattr(signal, name), name[3:].lower()) for name in dir(signal) |
| 50 | if name[:3] == "SIG" and name[3] != "_" |
| 51 | ) |
| 52 | |
| 53 | def __init__(self, app): |
| 54 | os.environ["SERVER_SOFTWARE"] = SERVER_SOFTWARE |
| 55 | |
| 56 | self._num_workers = None |
| 57 | self._last_logged_active_worker_count = None |
| 58 | self.log = None |
| 59 | |
| 60 | # Signal queue - SimpleQueue is reentrant-safe for signal handlers |
| 61 | self.SIG_QUEUE = queue.SimpleQueue() |
| 62 | |
| 63 | self.setup(app) |
| 64 | |
| 65 | self.pidfile = None |
| 66 | self.systemd = False |
| 67 | self.worker_age = 0 |
| 68 | self.reexec_pid = 0 |
| 69 | self.master_pid = 0 |
| 70 | self.master_name = "Master" |
| 71 | |
| 72 | # Dirty arbiter process |
| 73 | self.dirty_arbiter_pid = 0 |
| 74 | self.dirty_arbiter = None |
| 75 | self.dirty_pidfile = None # Well-known location for orphan detection |
| 76 | |
| 77 | # Control socket server |
| 78 | self._control_server = None |
| 79 | |
| 80 | # Stats tracking |
no outgoing calls