简体   繁体   English

调试打开 multiprocessing.Pipe()

[英]Debugging Open multiprocessing.Pipe()

I have a rather large program with multiple instances of multiprocessing.Pipe() being used.我有一个相当大的程序,其中使用了多个 multiprocessing.Pipe() 实例。 I'll refer to this program as test_pipe.我将把这个程序称为 test_pipe。 I'm seeing behavior where the test_pipe program hangs, and I'm trying to determine the reason the program is hanging.我看到 test_pipe 程序挂起的行为,我试图确定程序挂起的原因。 I have a suspicion that it's caused by a multiprocessing.Pipe() that is not being closed properly.我怀疑它是由未正确关闭的 multiprocessing.Pipe() 引起的。 As shown below, I use 'ps aux' to retrieve the PID of the test_pipe program while it is hung, and then I use 'lsof -p PID' to list the files that are still open by the test_pipe program.如下所示,我使用 'ps aux' 在 test_pipe 程序挂起时检索它的 PID,然后我使用 'lsof -p PID' 列出仍然由 test_pipe 程序打开的文件。 The test_pipe program lists two open pipes as shown. 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

My question is, given the pipe entries in the lsof output, is there any way to match these entries to the multiprocessing.Pipe() instances in my test_pipe program?我的问题是,鉴于 lsof output 中的 pipe 条目,有没有办法将这些条目与我的 test_pipe 程序中的 multiprocessing.Pipe() 实例匹配? For example, if there was a node() function of a multiprocessing Connection, then I could just log each connection's node and that would provide me with enough info on which of the many pipes within the test_pipe program to focus on.例如,如果有一个多处理连接的 node() function,那么我可以只记录每个连接的节点,这将为我提供有关 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() is not a real function, but is there maybe a way to derive this information from the Connection's fileno() function? node() 不是真正的 function,但有没有办法从 Connection 的 fileno() function 中获取此信息? I'm also happy to move away from this lsof-based approach if there are other suggestions.如果有其他建议,我也很乐意放弃这种基于 lsof 的方法。 My main goal is the quickly narrow in on a problem Pipe given a large program that uses Pipes in many places我的主要目标是快速缩小问题 Pipe 给定一个在许多地方使用管道的大型程序

ls /proc/<pid>/fd will show all the file descriptors open in a process, and the fileno() method will return the number you need to correlate the connection object within the process. ls /proc/<pid>/fd将显示在一个进程中打开的所有文件描述符,并且fileno()方法将返回您需要在进程内关联 object 的连接数。

More info 更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM