executor.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:yawn 作者: aclowes 项目源码 文件源码
def start_subprocess(self, execution_id: int, command: str, environment: dict, timeout: int) -> None:
        """
        Start a subprocess:
        - extend the parent process's environment with custom environment variables
        - track stdout and stderr file descriptors for later reading
        - set process group to facilitate killing any children of the command

        :param execution_id: the ID of the Execution instance being run
        :param command: a list of arguments, first argument must be an executable
        :param environment: environment variables from the WorkflowRun
        :param timeout: maximum number of seconds the process should be allowed to run for
        """
        process_environment = os.environ.copy()
        for key, value in environment.items():
            # all variables must be strings, be explicit so it fail in our code
            process_environment[key] = str(value)

        logger.info('Starting execution #%s', execution_id)

        process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                                   preexec_fn=os.setpgrp, env=process_environment, shell=True)

        # store references to the process and file descriptors
        # Popen gives us io.BufferedReader; get the raw file handle instead
        execution = Execution(process, execution_id, timeout)
        self.pipes.update({
            process.stdout.raw: execution,
            process.stderr.raw: execution
        })
        self.running[execution_id] = execution
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号