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

修复了python3.8及以上版本非windows系统不能监听配置的BUG #125

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

runzhi214
Copy link

修复了ISSUE:#124
BUG在于:python3.8,3.9,3.10中,

  • 启动multiprocessing的时候会把process_mgr和callback_tread_pool也尝试序列话
  • 没有使用从mp库中引入的RLock(即pulling_lock和server_list_lock类型错误)。

…mulitprocessing库的RLock. 同时,把callback_tread_pool和process_mgr标记为transient,因为没有序列化的必要)
…,RLock改用mulitprocessing库的RLock. 同时,把callback_tread_pool和process_mgr标记为transient,因为没有序列化的必要)"

This reverts commit 05e30aa.
在非windows环境改用mp库中的RLock,同时将不需要序列话的process_mgr和callback_tread_pool标记为transient

FIX TO ISSUE nacos-group#124
@runzhi214
Copy link
Author

@realJackSun

@chenhao26-nineteen
Copy link

@runzhi214 用这个方式改了,似乎可以 ,我是MacOs的系统,但是报了一个新的错误,能辛苦解答下吗
image

Can't pickle local object 'MyTestCase.test_add_config_watch..test_cb'

…t_list_naming_instance_online需要配合本地服务(实际已经成功)

FIX TO ISSUE nacos-group#124

Info to
nacos-group#125
@runzhi214
Copy link
Author

runzhi214 commented Dec 7, 2022

这个问题是由于test_client.py中使用了nested class和nested function导致的(因为pickle不允许),把他们重命名并放在测试类外部就可以通过了.

本地全部通过。其中,test_list_naming_instance_online这个测试方法需要单独测试,因为没有发送heartbeat的方法会马上死掉,在心跳结束之前可以看到测试通过。


class ShareFakeWatcher:
    content = None
    count = 0


def test_cb_fake_watcher(args):
    print(args)
    ShareFakeWatcher.count += 1
    ShareFakeWatcher.content = args["content"]


class ShareLongPulling:
    content = None


def cb_long_pulling(x):
    ShareLongPulling.content = x["content"]
    print(ShareLongPulling.content)

class TestClient(unittest.TestCase):
    ...
    def test_fake_watcher(self):
        d = "test"
        g = "DEFAULT_GROUP"

        cache_key = "+".join([d, g, NAMESPACE])

        client.add_config_watcher(d, g, test_cb_fake_watcher)
        client.add_config_watcher(d, g, test_cb_fake_watcher)
        client.add_config_watcher(d, g, test_cb_fake_watcher)
        time.sleep(1)
        client.notify_queue.put((cache_key, "xxx", "md51"))
        time.sleep(1)
        self.assertEqual(ShareFakeWatcher.content, "xxx")
        self.assertEqual(ShareFakeWatcher.count, 3)

        client.remove_config_watcher(d, g, test_cb_fake_watcher)
        ShareFakeWatcher.count = 0
        client.notify_queue.put((cache_key, "yyy", "md52"))
        time.sleep(1)
        self.assertEqual(ShareFakeWatcher.content, "yyy")
        self.assertEqual(ShareFakeWatcher.count, 2)

        client.remove_config_watcher(d, g, test_cb_fake_watcher, True)
        ShareFakeWatcher.count = 0
        client.notify_queue.put((cache_key, "not effective, no watchers", "md53"))
        time.sleep(1)
        self.assertEqual(ShareFakeWatcher.content, "yyy")
        self.assertEqual(ShareFakeWatcher.count, 0)

        ShareFakeWatcher.count = 0
        client.add_config_watcher(d, g, test_cb_fake_watcher)
        time.sleep(1)
        client.notify_queue.put((cache_key, "zzz", "md54"))
        time.sleep(1)
        self.assertEqual(ShareFakeWatcher.content, "zzz")
        self.assertEqual(ShareFakeWatcher.count, 1)

        ShareFakeWatcher.count = 0
        client.notify_queue.put((cache_key, "not effective, md5 no changes", "md54"))
        time.sleep(1)
        self.assertEqual(ShareFakeWatcher.content, "zzz")
        self.assertEqual(ShareFakeWatcher.count, 0)

    def test_long_pulling(self):
        client2 = nacos.NacosClient(SERVER_ADDRESSES, username=USERNAME, password=PASSWORD)
        d = "test1_pulling"
        g = "Group1"
        g2 = "Group2"

        client2.publish_config(d, g, "test2")
        client2.publish_config(d, g2, "test2")
        time.sleep(0.5)
        # test common
        client2.add_config_watcher(d, g, cb_long_pulling)
        client2.add_config_watcher(d, g2, cb_long_pulling)
        time.sleep(0.5)
        client2.publish_config(d, g, "test")
        client2.publish_config(d, g2, "test")
        time.sleep(1)
        self.assertEqual(ShareLongPulling.content, "test")
        client2.publish_config(d, g2, u"test2中文")
        time.sleep(1)
        self.assertEqual(ShareLongPulling.content, u"test2中文")

截屏2022-12-07 17 28 38

截屏2022-12-07 17 30 16

@shouldsee
Copy link

python一旦涉及到pickling和multiprocessing移植性就变得很差啊。。。

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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

Successfully merging this pull request may close these issues.

4 participants