safe_popen.py 文件源码

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

项目:tabkit 作者: yandex-tabkit 项目源码 文件源码
def safe_system(command, catch_sigpipe=False):
    popen = Popen(
        args = safe_popen_args(command),
        shell = False,
        preexec_fn = lambda: signal(SIGPIPE, SIG_DFL),
    )

    status = popen.wait() # pylint: disable-msg=E1101

    if status == 0:
        return status # ??? OK

    if catch_sigpipe:
        if status & 128 == 128 and status & 127 == SIGPIPE:
            return status # bash ??????? ???, ??? ??? ????? ?????? SIGPIPE
        elif status < 0 and -status == SIGPIPE:
            return status # bash ????? ?????? SIGPIPE
            # ?????? bash ?????? fork/exec ?????? ?????? exec (???????????, ?? ??????
            # ????? ????? ????????? ???? ??????? ???????) ? ????? ??????? ??? ????????
            # ???, ??? ????? ?????? ?????? ???, ???? ?? ????? ???? ???? ??? ????? ???.

    # ?????-?? ?????? (???????? ?? SIGPIPE ??? catch_sigpipe=True)
    raise SafePopenError(command, status)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号