在奇异容器内运行python子进程

问题描述

我试图像这样在Singularity容器中运行python子进程:

singularity exec image_name python python_task.py

在python_task.py中,它使用cmd调用函数

def run_shell_cmd(cmd):
    p = subprocess.Popen(
        ['/bin/bash','-o','pipefail'],# to catch error in pipe
        stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,universal_newlines=True,preexec_fn=os.setsid)  # to make a new process with a new PGID
    pid = p.pid
    pgid = os.getpgid(pid)
    log.info('run_shell_cmd: PID={},PGID={},CMD={}'.format(pid,pgid,cmd))
    t0 = get_ticks()
    stdout,stderr = p.communicate(cmd)
    rc = p.returncode
    t1 = get_ticks()
    err_str = (
        'PID={pid},PGID={pgid},RC={rc},DURATION_SEC={dur:.1f}\n'
        'STDERR={stde}\nSTDOUT={stdo}'
    ).format(
        pid=pid,pgid=pgid,rc=rc,dur=t1 - t0,stde=stderr.strip(),stdo=stdout.strip()
    )
    
    if rc:
        # kill all child processes
        try:
            os.killpg(pgid,signal.SIGKILL)
        except:
            pass
        finally:
            raise Exception(err_str)
    else:
        log.info(err_str)
    return stdout.strip('\n')

但是我收到此错误/异常

Exception: PID=23793,PGID=23793,RC=255,DURATION_SEC=0.1
STDERR=WARNING: Could not lookup the current user's @R_700_4045@ion: user: unkNown userid 29931
FATAL:   Couldn't determine user account @R_700_4045@ion: user: unkNown userid 29931

有关如何更正此问题的任何建议?我认为userid 29931不存在于容器内,这导致此错误。但是我不确定该如何解决

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)