From 448a76dadeccdb6cff123825b9aec5d8657f028b Mon Sep 17 00:00:00 2001 From: runzhi214 Date: Thu, 1 Dec 2022 18:33:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86py3.8+(=E5=90=AB3.8,?= =?UTF-8?q?3.9,3.10)=E7=9A=84=E7=9B=91=E5=90=AC=E9=85=8D=E7=BD=AE=E6=97=B6?= =?UTF-8?q?=E6=8A=A5=E9=94=99not=20serializable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在非windows环境改用mp库中的RLock,同时将不需要序列话的process_mgr和callback_tread_pool标记为transient FIX TO ISSUE https://github.com/nacos-group/nacos-sdk-python/issues/124 --- nacos/client.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/nacos/client.py b/nacos/client.py index ff527ad..e8d822a 100644 --- a/nacos/client.py +++ b/nacos/client.py @@ -15,6 +15,7 @@ from multiprocessing import Process, Manager, Queue, pool from threading import RLock, Thread +from multiprocessing import RLock as PRLock try: # python3.6 @@ -251,13 +252,19 @@ def __init__(self, server_addresses, endpoint=None, namespace=None, ak=None, sk= self.username = username self.password = password - self.server_list_lock = RLock() + if platform.system() == "windows": + self.server_list_lock = RLock() + else: + self.server_list_lock = PRLock() self.server_offset = 0 self.watcher_mapping = dict() self.subscribed_local_manager = SubscribedLocalManager() self.subscribe_timer_manager = NacosTimerManager() - self.pulling_lock = RLock() + if platform.system() == "windows": + self.pulling_lock = RLock() + else: + self.pulling_lock = PRLock() self.puller_mapping = None self.notify_queue = None self.callback_tread_pool = None @@ -1163,6 +1170,17 @@ def stop_subscribe(self): """ self.subscribe_timer_manager.stop() + def __getstate__(self): + self_dict = self.__dict__.copy() + # pool object cannot be passed + del self_dict['callback_tread_pool'] + # weak-ref object cannot be pickled + del self_dict['process_mgr'] + return self_dict + + def __setstate__(self, state): + self.__dict__.update(state) + if DEBUG: NacosClient.set_debugging()