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()