pyzmq插座手柄泄漏?

2024-06-02 15:51:26 发布

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

嗨,StackOverflow的好人。在

我使用的是pyzmq,我有一些长时间运行的进程,这导致了一个发现,套接字句柄是开放的。我将违规代码缩小到以下几点:

import zmq

uri = 'tcp://127.0.0.1'
sock_type = zmq.REQ
linger = 250

# Observe output of lsof -p <pid> here and see no socket handles

ctx = zmq.Context.instance()
sock = ctx.socket(sock_type)
sock.setsockopt(zmq.LINGER, linger)
port = sock.bind_to_random_port(uri)

# Observe output of lsof -p <pid> here and see many socket handles

sock.close()  # lsof -p <pid> still showing many socket handles
ctx.destroy()  # Makes no difference

pyzmq版本是pyzmq-13.1.0

要么是pyzmq中有一个bug,要么是我做错了什么。我希望你能帮助我!!在

谢谢!在


Tags: ofoutputheretypeurisocketpyzmqzmq
1条回答
网友
1楼 · 发布于 2024-06-02 15:51:26

在与pieterh和minrk在zeromq上聊天后,我们找到了原因。在

13.1.0中的ctx.destroy()有一个缩进错误,因此只有在存在未闭合的套接字时才会调用Context.term()。在

解决方法:改为调用ctx.term(),并确保在关闭之前关闭所有套接字。在

相关问题 更多 >