Skip to content

Commit

Permalink
修复了py3.8+(含3.8,3.9,3.10)的监听配置时报错not serializable
Browse files Browse the repository at this point in the history
在非windows环境改用mp库中的RLock,同时将不需要序列话的process_mgr和callback_tread_pool标记为transient

FIX TO ISSUE nacos-group#124
  • Loading branch information
runzhi214 committed Dec 1, 2022
1 parent 63d37a7 commit 448a76d
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions nacos/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()

0 comments on commit 448a76d

Please sign in to comment.