python - 无法使用 Popen() 可靠地打开子进程——OSError [Errno 14] Bad Address

标签 python subprocess

我正在尝试使用 subprocess32.Popen() 在 Python (2.7) 下打开多个子进程——每个子进程都运行相同的预编译二进制文件,但对唯一目录中的文件进行操作。大多数时候一切正常,但我经常收到 OSError [Errno 14] Bad Address。这是代码:

self.gld_stdout_file = open('stdout', 'w+')
self.gld_stderr_file = open('stderr', 'w+')
...
subprocess.Popen(string.join(gld_open_str, " "), shell=True, stderr=self.gld_stderr_file,
                 stdout=self.gld_stdout_file, bufsize=-1, close_fds=ON_POSIX,
                 env={'TEMP':temp_path})

此错误发生在大约 5-10% 的尝试使用 Popen() 时,而同一循环中的其他 Popen() 调用工作得很好。环顾四周,这似乎可能来自较低级别的套接字调用中的错误,我没有直接连接。 (例如 Herehere )

关于我为什么会收到此错误的任何想法?

更重要的是:

我该如何解决?

作为引用,我们使用的是 subprocess32,据称它可以通过多个子进程调用提供更高的稳定性。此外,如果相关的话,整个方案被包装到一个更大的基于 MPI 的 HPC 并行调用中,这样多个计算节点就会尝试同时做同样的事情。由于担心多次尝试执行同一文件可能会出现冲突或文件系统挑战,我们已经在执行前将二进制文件复制到每个节点。

此外,我在使用 shell=False 时看到了同样的问题:

subprocess.Popen(gld_open_list, shell=False, stderr=self.gld_stderr_file,
                 stdout=self.gld_stdout_file, bufsize=-1, close_fds=ON_POSIX,
                 env={'TEMP':temp_path})

最佳答案

这是 python2.6 上的一个错误,已在 2.7 上修复。

IOError 由于读取系统调用从其中返回 EINTR 而引发 方法(read()readline()readlines())。

见: https://github.com/python/cpython/commit/736ca00270db72fefa5fb278982c96e5e7139d72

https://github.com/python/cpython/blob/2.6/Objects/fileobject.c#L1362 .

升级你的 python,然后一切都很有趣。

关于python - 无法使用 Popen() 可靠地打开子进程——OSError [Errno 14] Bad Address,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36397853/

相关文章:

python - 子集和组合不同长度数组的有效方法

python - 将 subprocess.check_output 用于带有 2>/dev/null 的命令

python - 使用网络浏览器调用的python脚本运行exe

python - 如何使用 Python 子进程在 Windows 中进行搜索

python - 从本地机器上的 psycopg2 连接到 Docker 上的 PostgreSQL 数据库

python - 在 Python 中通过套接字发送的字符串一旦 .recv'd 后将不会与等效字符串进行比较

python - 在 R 中执行 mysql 更新查询的任何更快的方法?在 python ?

python - 大于或等于python中的分箱

python - 选择 python popen process.kill() 或 process.terminate() 的更优雅的方法

python - 处理外部流程