Python和卡迪:断管E

2024-06-06 20:58:37 发布

您现在位置:Python中文网/ 问答频道 /正文

设置如下:我使用Kaldi工具。它们在某种形式的bash脚本中被称为。这些bash脚本由python编写的包装程序调用,该程序将任务提交给Sun网格引擎。在

我要执行的命令如下

feat-to-dim 'ark:copy-feats scp:train.scp ark:- |' -

在命令行中执行此操作,将生成正确的结果“40”以及警告

^{pr2}$

但是,如果我用以下方式包装:

python -c "import os; os.system(\"feat-to-dim 'ark:copy-feats scp:train.scp ark:- |' -\")"

程序copy-feats失败,错误为:

ERROR (copy-feats[5.0.23-f7b2f]:Write():kaldi-matrix.cc:1240) Failed to write matrix to stream

在各种堆栈跟踪和以下错误之后,将额外打印以下警告:

WARNING (feat-to-dim[5.0.23-f7b2f]:Close():kaldi-io.cc:501) Pipe copy-feats scp:train.scp ark:- | had nonzero return status 134

这就是我发现的:feat-to-dim提前关闭管道,而copy-feats试图继续写入输出。由于不可能,copy-feats被终止。13可能表示管道破裂错误。在

对于Python来说,这是一个严重的问题,为什么它会将其转换为错误并终止。但是在本例中,不是Python产生了这个错误,而是copy-feats。因此,像python中的try/catchtrapping the pipe这样的东西在本例中似乎没有任何成功。在

此外,以下几行操作非常好,没有任何警告或错误:

python -c "import os; os.system(\"copy-feats scp:train.scp ark:-\")" > cp
python -c "import os; os.system(\"feat-to-dim ark:cp -\")"

下面一行生成简单的错误消息cat: write error: Broken pipe和退出状态256:

python -c "import os; os.system(\"feat-to-dim ark:'cat cp |' -\")"

你还有什么进一步的建议吗?在


Tags: toimport程序警告os错误trainsystem
1条回答
网友
1楼 · 发布于 2024-06-06 20:58:37

13 probably indicates the broken pipe error.

13是一个答案(特征维度),你可以使用它作为结果,你可以忽略所有像这样的错误

with open(os.devnull, "w") as devnull:
    subprocess.call("feat-to-dim 'ark:copy-feats scp:feats.scp ark:- |' -", shell=True, stderr=devnull)

This is what I've found out: feat-to-dim closes the pipe in advance whereas copy-feats tries to continue writing output.

这是一个kaldi设计,它试图只读取第一个特性,并简单地转储其余的特性,但是由于管道没有终止writer child的方法,它不得不以一种糟糕的方式退出。一个选项是读取feat中的完整子输出以使其变暗,但这会比较慢。在

你可以打开Kaldi bug。在

相关问题 更多 >