Skip to content

Commit

Permalink
Make Worker.pid useful in master process
Browse files Browse the repository at this point in the history
  • Loading branch information
jonashaag authored and Jonas Haag committed Nov 25, 2016
1 parent 53fd1c1 commit f671d51
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
7 changes: 4 additions & 3 deletions gunicorn/arbiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,14 +548,15 @@ def spawn_worker(self):
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)
Expand All @@ -573,7 +574,7 @@ def spawn_worker(self):
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)
Expand Down
5 changes: 1 addition & 4 deletions gunicorn/workers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(self, age, ppid, sockets, app, timeout, cfg, log):
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
Expand All @@ -57,10 +58,6 @@ def __init__(self, age, ppid, sockets, app, timeout, cfg, log):
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
Expand Down

0 comments on commit f671d51

Please sign in to comment.