Skip to content

Commit

Permalink
display number of workers in process title.
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitc committed Aug 8, 2011
1 parent d189e0c commit 01b107e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
14 changes: 8 additions & 6 deletions pistil/arbiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ def on_init(self, args):

def on_init_process(self):
""" method executed when we init a process """
pass


def init_process(self):
"""\
Expand All @@ -143,7 +145,7 @@ def init_process(self):

# set current pid
self.pid = os.getpid()

util.set_owner_process(self.conf.get("uid", os.geteuid()),
self.conf.get("gid", os.getegid()))

Expand All @@ -153,9 +155,10 @@ def init_process(self):
# prevent fd inheritance
util.close_on_exec(self.tmp.fileno())

# init signals
# init signals
self.init_signals()

util._setproctitle("arbiter [%s]" % self.name)
self.on_init_process()

log.debug("Arbiter %s booted on %s", self.name, self.pid)
Expand Down Expand Up @@ -189,9 +192,7 @@ def signal(self, sig, frame):
log.warn("Dropping signal: %s", sig)

def run(self):
"Main master loop."
util._setproctitle("arbiter [%s]" % self.name)

"Main master loop."
if not self.booted:
return self.init_process()

Expand All @@ -218,7 +219,8 @@ def run(self):
log.error("Unhandled signal: %s", signame)
continue
log.info("Handling signal: %s", signame)
handler()
handler()
self.tmp.notify()
self.wakeup()
except StopIteration:
self.halt()
Expand Down
12 changes: 10 additions & 2 deletions pistil/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class PoolArbiter(Arbiter):


SIGNALS = map(
_SIGNALS = map(
lambda x: getattr(signal, "SIG%s" % x),
"HUP QUIT INT TERM TTIN TTOU USR1 USR2 WINCH".split()
)
Expand Down Expand Up @@ -65,18 +65,25 @@ def __init__(self, args, spec=(), name=None,
self.booted = False
self.stopping = False
self.debug =self.conf.get("debug", False)
self.tmp = WorkerTmp(self.conf)
self.tmp = WorkerTmp(self.conf)

def update_proc_title(self):
util._setproctitle("arbiter [%s running %s workers]" % (self.name,
self.num_workers))

def on_init(self, conf):
return None

def on_init_process(self):
self.update_proc_title()

def handle_ttin(self):
"""\
SIGTTIN handling.
Increases the number of workers by one.
"""
self.num_workers += 1
self.update_proc_title()
self.manage_workers()

def handle_ttou(self):
Expand All @@ -87,6 +94,7 @@ def handle_ttou(self):
if self.num_workers <= 1:
return
self.num_workers -= 1
self.update_proc_title()
self.manage_workers()

def reload(self):
Expand Down
1 change: 1 addition & 0 deletions pistil/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
try:
from setproctitle import setproctitle
def _setproctitle(title):
print(title)
setproctitle(title)
except ImportError:
def _setproctitle(title):
Expand Down
1 change: 1 addition & 0 deletions pistil/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def run(self):

def on_init_process(self):
""" method executed when we init a process """
pass

def init_process(self):
"""\
Expand Down

0 comments on commit 01b107e

Please sign in to comment.