MCPcopy
hub / github.com/benoitc/gunicorn / init_process

Method init_process

gunicorn/workers/base.py:86–144  ·  view source on GitHub ↗

\ If you override this method in a subclass, the last statement in the function should be to call this method with super().init_process() so that the ``run()`` loop is initiated.

(self)

Source from the content-addressed store, hash-verified

84 raise NotImplementedError()
85
86 def init_process(self):
87 """\
88 If you override this method in a subclass, the last statement
89 in the function should be to call this method with
90 super().init_process() so that the ``run()`` loop is initiated.
91 """
92
93 # set environment' variables
94 if self.cfg.env:
95 for k, v in self.cfg.env.items():
96 os.environ[k] = v
97
98 util.set_owner_process(self.cfg.uid, self.cfg.gid,
99 initgroups=self.cfg.initgroups)
100
101 # Reseed the random number generator
102 util.seed()
103
104 # For waking ourselves up
105 self.PIPE = os.pipe()
106 for p in self.PIPE:
107 util.set_non_blocking(p)
108 util.close_on_exec(p)
109
110 # Prevent fd inheritance
111 for s in self.sockets:
112 util.close_on_exec(s)
113 util.close_on_exec(self.tmp.fileno())
114
115 self.wait_fds = self.sockets + [self.PIPE[0]]
116
117 self.log.close_on_exec()
118
119 self.init_signals()
120
121 # start the reloader
122 if self.cfg.reload:
123 def changed(fname):
124 self.log.info("Worker reloading: %s modified", fname)
125 self.alive = False
126 os.write(self.PIPE[1], b"1")
127 self.cfg.worker_int(self)
128 time.sleep(0.1)
129 sys.exit(0)
130
131 self.log.warning("Reloader is on. Use in development only!")
132 reloader_cls = reloader_engines[self.cfg.reload_engine]
133 self.reloader = reloader_cls(extra_files=self.cfg.reload_extra_files,
134 callback=changed)
135
136 self.load_wsgi()
137 if self.reloader:
138 self.reloader.start()
139
140 self.cfg.post_worker_init(self)
141
142 # Enter main run loop
143 self.booted = True

Calls 9

init_signalsMethod · 0.95
load_wsgiMethod · 0.95
runMethod · 0.95
itemsMethod · 0.80
post_worker_initMethod · 0.80
close_on_execMethod · 0.45
filenoMethod · 0.45
warningMethod · 0.45
startMethod · 0.45