gpt4 book ai didi

python - ZeroMQ 在套接字绑定(bind)到 ipc ://protocol address (python) 时抛出 ZMQError

转载 作者:行者123 更新时间:2023-12-03 12:02:14 37 4
gpt4 key购买 nike

我正在尝试在 Python 中使用带有 ZeroMQ 的 IPC 协议(protocol)。

import sys
import time

from random import randint

import zmq

def main(url=None):
ctx = zmq.Context.instance()
publisher = ctx.socket(zmq.PUB)
if url:
publisher.bind(url)
else:
publisher.bind('ipc://var/run/fast-service')
# Ensure subscriber connection has time to complete
time.sleep(1)

# Send out all 1,000 topic messages
for topic_nbr in range(1000):
publisher.send_multipart([
b"%03d" % topic_nbr,
b"Save Roger",
])

if __name__ == '__main__':
main(sys.argv[1] if len(sys.argv) > 1 else None)

它给出了以下错误:
Traceback (most recent call last):
File "pathopub.py", line 43, in <module>
main(sys.argv[1] if len(sys.argv) > 1 else None)
File "pathopub.py", line 19, in main
publisher.bind("ipc://var/run/fast-service")
File "zmq/backend/cython/socket.pyx", line 547, in zmq.backend.cython.socket.Socket.bind
zmq.error.ZMQError: No such file or directory for ipc path "var/run/fast-service".
我不明白为什么 socket.bind() 会发生这种情况函数,因为在 documentation它说:

When binding a socket to a local address using zmq_bind() with the ipc transport, the endpoint shall be interpreted as an arbitrary string identifying the pathname to create.


这意味着不必提供已创建的目录。

最佳答案

URL 方案是 ipc:// .需要添加绝对路径/var/run/fast-service .所以,

publisher.bind('ipc:///var/run/fast-service')
更一般的 URL 是 ipc://<host>/<path> .您需要本地主机,因此该部分为空。文件系统 URL 类似, file:///home/foo/bar.txt引用资料 /home/foo/bar.txt在本地主机上。

关于python - ZeroMQ 在套接字绑定(bind)到 ipc ://protocol address (python) 时抛出 ZMQError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64273155/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com