Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NNGException when msg port is not ready yet #132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion clients/python/wcferry/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,6 @@ def enable_receiving_msg(self, pyq=False) -> bool:
"""允许接收消息,成功后通过 `get_msg` 读取消息"""
def listening_msg():
rsp = wcf_pb2.Response()
self.msg_socket.dial(self.msg_url, block=True)
while self._is_receiving_msg:
try:
rsp.ParseFromString(self.msg_socket.recv_msg().bytes)
Expand All @@ -540,6 +539,19 @@ def listening_msg():
if rsp.status != 0:
return False

fail_cnt = 0
while True:
try:
self.msg_socket.dial(self.msg_url, block=True)
break
except pynng.exceptions.NNGException as e:
if fail_cnt > 50:
raise e
fail_cnt += 1
sleep(0.1) # 等待消息端口启动监听
except Exception as e:
raise e

self._is_receiving_msg = True
# 阻塞,把控制权交给用户
# self.listening_msg(callback)
Expand Down