resource.py 文件源码

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

项目:concourse-ansible-resource 作者: SpringerPE 项目源码 文件源码
def process(self, cmd=[], input=None, timeout=None):
        proc = subprocess.Popen(cmd,
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        self.logger.info('Running process, pid=%d: %s' % (proc.pid, str(cmd)))
        try:
            output, err = proc.communicate(input, timeout=timeout)
        except subprocess.TimeoutExpired as e:
            self.logger.warning(
                'Process %d killed with timeout %s' % (proc.pid, str(timeout)))
            proc.kill()
            output, err = proc.communicate()
        self.logger.debug("stdout: " + repr(output))
        self.logger.debug("stderr: " + repr(err))
        stdout = output.decode('utf-8')
        stderr = err.decode('utf-8')
        if proc.returncode != 0:
            self.logger.warning(
                'Process %d failed with rcode %d' % (proc.pid, int(proc.returncode)))
        else:
            self.logger.debug('Process %d finished with rcode 0' % (proc.pid))
        return int(proc.returncode), stdout, stderr
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号