Make Worker.pid useful in master process

This commit is contained in:
Jonas Haag 2016-11-18 11:30:43 +01:00 committed by Jonas Haag
parent 53fd1c1071
commit f671d51f76
2 changed files with 5 additions and 7 deletions

View File

@ -548,14 +548,15 @@ class Arbiter(object):
self.cfg.pre_fork(self, worker)
pid = os.fork()
if pid != 0:
worker.pid = pid
self.WORKERS[pid] = worker
return pid
# Process Child
worker_pid = os.getpid()
worker.pid = os.getpid()
try:
util._setproctitle("worker [%s]" % self.proc_name)
self.log.info("Booting worker with pid: %s", worker_pid)
self.log.info("Booting worker with pid: %s", worker.pid)
self.cfg.post_fork(self, worker)
worker.init_process()
sys.exit(0)
@ -573,7 +574,7 @@ class Arbiter(object):
sys.exit(self.WORKER_BOOT_ERROR)
sys.exit(-1)
finally:
self.log.info("Worker exiting (pid: %s)", worker_pid)
self.log.info("Worker exiting (pid: %s)", worker.pid)
try:
worker.tmp.close()
self.cfg.worker_exit(self, worker)

View File

@ -38,6 +38,7 @@ class Worker(object):
changes you'll want to do that in ``self.init_process()``.
"""
self.age = age
self.pid = "[booting]"
self.ppid = ppid
self.sockets = sockets
self.app = app
@ -57,10 +58,6 @@ class Worker(object):
def __str__(self):
return "<Worker %s>" % self.pid
@property
def pid(self):
return os.getpid()
def notify(self):
"""\
Your worker subclass must arrange to have this method called