| 293 | return interpreter if interpreter else 'python' |
| 294 | |
| 295 | def start(self, cb=None): |
| 296 | self.check_start_end_time() |
| 297 | |
| 298 | executor = file_quote(os.path.join( |
| 299 | os.path.dirname(u_encode(__file__)), 'process_executor.py' |
| 300 | )) |
| 301 | |
| 302 | interpreter = self._get_python_interpreter() |
| 303 | |
| 304 | cmd = [interpreter, executor, self.cmd] |
| 305 | cmd.extend(self.args) |
| 306 | |
| 307 | current_app.logger.info( |
| 308 | "Executing the process executor with the arguments: %s", |
| 309 | str(cmd) |
| 310 | ) |
| 311 | |
| 312 | # Acquiring lock while copying the environment from the parent process |
| 313 | # for the child process |
| 314 | with ConnectionLocker(_is_kerberos_conn=False): |
| 315 | # Make a copy of environment, and add new variables to support |
| 316 | env = os.environ.copy() |
| 317 | |
| 318 | env['PROCID'] = self.id |
| 319 | env['OUTDIR'] = self.log_dir |
| 320 | env['PGA_BGP_FOREGROUND'] = "1" |
| 321 | if config.SERVER_MODE and session and \ |
| 322 | session.get('auth_source_manager', {}).get( |
| 323 | 'current_source') == KERBEROS and \ |
| 324 | 'KRB5CCNAME' in session: |
| 325 | env['KRB5CCNAME'] = session['KRB5CCNAME'] |
| 326 | |
| 327 | if self.env: |
| 328 | env.update(self.env) |
| 329 | |
| 330 | current_app.logger.debug(self.env) |
| 331 | |
| 332 | if cb is not None: |
| 333 | cb(env) |
| 334 | if os.name == 'nt': |
| 335 | DETACHED_PROCESS = 0x00000008 |
| 336 | from subprocess import CREATE_NEW_PROCESS_GROUP |
| 337 | |
| 338 | # We need to redirect the standard input, standard output, and |
| 339 | # standard error to devnull in order to allow it start in detached |
| 340 | # mode on |
| 341 | stdout = os.devnull |
| 342 | stderr = stdout |
| 343 | stdin = open(os.devnull, "r") |
| 344 | stdout = open(stdout, "a") |
| 345 | stderr = open(stderr, "a") |
| 346 | |
| 347 | p = Popen( |
| 348 | cmd, |
| 349 | close_fds=False, |
| 350 | env=env, |
| 351 | stdout=stdout.fileno(), |
| 352 | stderr=stderr.fileno(), |