【发布时间】:2021-08-24 22:56:48
【问题描述】:
我有一个相当大的程序,其中使用了多个 multiprocessing.Pipe() 实例。我将把这个程序称为 test_pipe。我看到的行为 test_pipe 程序挂起,我正在尝试确定程序挂起的原因。我怀疑它是由 multiprocessing.Pipe() 引起的 没有正确关闭。如下所示,我使用 'ps aux' 在 test_pipe 程序挂起时检索它的 PID,然后我使用 'lsof -p PID' 列出正在运行的文件 仍然由 test_pipe 程序打开。 test_pipe 程序列出了两个打开的管道,如图所示。
root@container:~# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 49 1.8 0.2 1020008 40068 ? Sl Jun06 19:57 python3 -m test.test_pipe
root@container:~# lsof -p 49
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
test_pipe 21 root 1w FIFO 0,13 0t0 19391346 pipe
test_pipe 21 root 2w FIFO 0,13 0t0 19391347 pipe
我的问题是,鉴于 lsof 输出中的管道条目,有没有办法将这些条目与我的 test_pipe 程序中的 multiprocessing.Pipe() 实例相匹配?例如,如果 有一个多处理连接的 node() 函数,然后我可以只记录每个连接的节点,这将为我提供有关 test_pipe 程序中的许多管道中的哪些管道需要关注的足够信息。
from multiprocessing import Pipe, Process
parent_conn, child_conn = Pipe()
print(f"Parent pipe has node: {parent_conn.node()}") # node() is NOT a real function, but just used for demonstration purposes
node() 不是一个真正的函数,但有没有办法从 Connection 的 fileno() 函数中获取这些信息?如果有其他建议,我也很乐意放弃这种基于 lsof 的方法。我的主要目标是快速缩小问题 Pipe 给定一个在许多地方使用 Pipes 的大型程序
【问题讨论】: