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

_process_polling_result 队列控制问题 #190

Open
yifur opened this issue Nov 30, 2024 · 1 comment
Open

_process_polling_result 队列控制问题 #190

yifur opened this issue Nov 30, 2024 · 1 comment

Comments

@yifur
Copy link

yifur commented Nov 30, 2024

当 watch 执行完后,线程仍在后台执行,notify_queue.get() 时读取不到数据导致异常。

客户端代码:

class InstallConfig:
    def __init__(self):
        logger.info("connect to nacos: {}, nameserver: {}, group: {}, dataId: {}",
                    NACOS_SERVER,
                    NACOS_NAMESPACE,
                    NACOS_GROUP,
                    NACOS_DATA_ID)

        self.client = nacos.NacosClient(NACOS_SERVER, namespace=NACOS_NAMESPACE)

        # 添加以下设置未能解决 add_config_watcher 退出时的线程异常
        # Exception in thread Thread-6 (_process_polling_result),
        # self.client.set_options(default_timeout=1)
        # self.client.set_options(pulling_timeout=1)
        # self.client.set_options(pulling_config_size=3)
        self.client.set_options(callback_thread_num=10)

        self.client.add_config_watcher(NACOS_DATA_ID, NACOS_GROUP, self.config_watcher)
        self.config = yaml.safe_load(self.client.get_config(NACOS_DATA_ID, NACOS_GROUP))

    def config_watcher(self, args):
        logger.info("run config watcher: {}", args)
        self.config = yaml.safe_load(args["raw_content"])


if __name__ == "__main__":
    config = InstallConfig()

    for i in range(10):
        print(config.get_minio_config().server)
        time.sleep(1)

watcher 队列异常,watcher 能接受消息,但在 for 之后报如下异常

Exception in thread Thread-14 (_process_polling_result):
Traceback (most recent call last):
  File "/root/anaconda3/envs/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/root/anaconda3/envs/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/root/anaconda3/envs/lib/python3.10/site-packages/nacos/client.py", line 817, in _process_polling_result
    cache_key, content, md5 = self.notify_queue.get()
  File "/root/anaconda3/envs/lib/python3.10/multiprocessing/queues.py", line 103, in get
    res = self._recv_bytes()
  File "/root/anaconda3/envs/lib/python3.10/multiprocessing/connection.py", line 216, in recv_bytes
    buf = self._recv_bytes(maxlength)
  File "/root/anaconda3/envs/lib/python3.10/multiprocessing/connection.py", line 414, in _recv_bytes
    buf = self._recv(4)
  File "/root/anaconda3/envs/lib/python3.10/multiprocessing/connection.py", line 383, in _recv
    raise EOFError
EOFError
@yifur
Copy link
Author

yifur commented Dec 8, 2024

已解决,需要手动往 queue 里 put
self.client.add_config_watcher(NACOS_DATA_ID, NACOS_GROUP, self.config_watcher)
self.client.notify_queue.put((cache_key, NACOS_NAMESPACE, "md5"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant