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)
| 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.""" |
no test coverage detected