代码之家  ›  专栏  ›  技术社区  ›  YANG ZHOU

使用asyncio.create_subprocess_shell运行sbatch不正常

  •  0
  • YANG ZHOU  · 技术社区  · 2 年前

    像这样的内容

    Class Tcontent:
        def __init__(self, op_file):
            self.op_file = op_file
        
        async def __aenter__(self):
            sbatch_cmd = f"sbatch -p test -q test -c 1 --mem 1000 -o {self.op_file} myscript.sh"
            proc = await asyncio.create_subprocess_shell(sbatch_cmd, stderr=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE)
            stdout, stderr = await proc.communicate()
            if proc.returncode != 0:
                raise Exception
            else:
                with open(op_file) as tf:
                    out = tf.read()
                return out
        async def __aexit__(self, exc_type, exc_val, exc_tb):
            ***
    

    那我叫它

    async with Tcontent('sbatch.out') as x:
        print(x)
    

    它将提高 No such file or directory sbatch.out

    在之前设置断点时 with open(op_file) as tf ,然后继续运行,效果良好

    0 回复  |  直到 2 年前