def exit_code(pid, timeout=5):

    start = time.time()
    while True:
        _, status = os.waitpid(pid, os.WNOHANG)
        if os.WIFEXITED(status):
            return os.WEXITSTATUS(status)
        else:
            if (time.time() - start) > timeout:
                return -1
Wait up to `timeout` seconds for `pid` to exit and return its exit code.
dataset/ETHPy150Open d11wtq/dockerpty/tests/util.py/exit_code