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

Method init_process

gunicorn/dirty/worker.py:142–176  ·  view source on GitHub ↗

Initialize the worker process after fork. This is called in the child process after fork. It sets up the environment, loads apps, and starts the main run loop.

(self)

Source from the content-addressed store, hash-verified

140 self.tmp.notify()
141
142 def init_process(self):
143 """
144 Initialize the worker process after fork.
145
146 This is called in the child process after fork. It sets up
147 the environment, loads apps, and starts the main run loop.
148 """
149 # Set environment variables
150 if self.cfg.env:
151 for k, v in self.cfg.env.items():
152 os.environ[k] = v
153
154 util.set_owner_process(self.cfg.uid, self.cfg.gid,
155 initgroups=self.cfg.initgroups)
156
157 # Reseed random number generator
158 util.seed()
159
160 # Prevent fd inheritance
161 util.close_on_exec(self.tmp.fileno())
162 self.log.close_on_exec()
163
164 # Set up signals
165 self.init_signals()
166
167 # Load dirty apps
168 self.load_apps()
169
170 # Call hook
171 self.pid = os.getpid()
172 self.cfg.dirty_worker_init(self)
173
174 # Enter main run loop
175 self.booted = True
176 self.run()
177
178 def init_signals(self):
179 """Set up signal handlers."""

Callers 1

spawn_workerMethod · 0.95

Calls 7

init_signalsMethod · 0.95
load_appsMethod · 0.95
runMethod · 0.95
itemsMethod · 0.80
close_on_execMethod · 0.45
filenoMethod · 0.45
dirty_worker_initMethod · 0.45

Tested by

no test coverage detected