nacos-group / nacos-sdk-python

nacos python sdk
Apache License 2.0
375 stars 139 forks source link

macOS big sur python3.9 使用 add_config_watcher 函数 TypeError: cannot pickle '_thread.RLock' object #45

Open losenli opened 3 years ago

losenli commented 3 years ago

if name == "main": client.add_config_watcher(data_id, group, test_cb) import time time.sleep(3000)

Traceback (most recent call last): File "/Users/lzh/micro_service/PythonStart/nacos_test/main.py", line 29, in client.add_config_watcher(data_id, group, test_cb) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/nacos/commons.py", line 10, in synced_func return func(*args, *kws) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/nacos/client.py", line 519, in add_config_watcher self.add_config_watchers(data_id, group, [cb], content) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/nacos/commons.py", line 10, in synced_func return func(args, **kws) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/nacos/client.py", line 565, in add_config_watchers puller.start() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/process.py", line 121, in start self._popen = self._Popen(self) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/context.py", line 224, in _Popen return _default_context.get_context().Process._Popen(process_obj) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/context.py", line 284, in _Popen return Popen(process_obj) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 32, in init super().init(process_obj) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_fork.py", line 19, in init self._launch(process_obj) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 47, in _launch reduction.dump(process_obj, fp) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/reduction.py", line 60, in dump ForkingPickler(file, protocol).dump(obj) TypeError: cannot pickle '_thread.RLock' object

Process finished with exit code 1

samandqq commented 3 years ago

可以尝试获取源码, 对client.py中,以下代码增加或等于Mac的条件, 尝试用多线程代替多进程的方式 if sys_os == 'Windows': puller = Thread(target=self._do_pulling, args=(key_list, self.notify_queue)) puller.setDaemon(True)