【发布时间】:2014-07-19 11:47:14
【问题描述】:
我有一个 python 脚本,它对一个状态缩写列表作为其单个参数进行操作,以及一个包含所有状态缩写字符串的文本文件。
正常通话是……
$ mypy.py "AK"
...在阿拉斯加运行脚本。
我目前正在使用以下内容对从我的 statelist.txt 文件中获取的每个州缩写运行脚本:
$ cat statelist.txt | xargs -n 1 ./mypy.py
我现在想要并行化执行,而 GNU Parallels 看起来是正确的选择。我看到from here这应该是替换xargs -n1的语法:
$ find . -name '*.html' | parallel gzip --best
所以,我的尝试是
$ cat statelist.txt | parallel python mypy.py
和
$ cat statelist.txt | parallel python mypy.py {}
但是这两个都返回了:
/bin/bash: mypy.py: command not found
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'AK' is not defined
它似乎是在未引用的情况下传递它?但是当我在 '{}' 中添加引号时,它会传入文字“{}”。
【问题讨论】:
-
第一次调用看起来不错,实际上。但是
/bin/bash: mypy.py: command not found看起来更像是你在一个不相关的错误 cwd 中。您可以尝试输入 mypy.py 的绝对路径吗? -
试试
cat statelist.txt | parallel python ./mypy.py -
相同,
Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'AK' is not defined这太奇怪了,因为另一个命令在之前完全相同的终端中运行良好。
标签: python bash parallel-processing xargs