Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
version: 2.0.1
python version: 3.8.13
operate system: CentOS Linux release 7.9.2009
while syntax cause high cpu use, because of the different mechanism, below code when run in linux, it will use hign cpu. windows normal
test code:
import nacos
import yaml
from flask import Flask
app = Flask(name)
class NacosCofig:
namespace = "public"
group = "DEFAULT_GROUP"
server_name = "test"
server_port = "7004"
data_id = "test"
server_addresses = "http://127.0.0.1:8848"
server_ip = "127.0.0.1"
client = nacos.NacosClient(NacosCofig.server_addresses, namespace=NacosCofig.namespace)
yaml_data = yaml.load(client.get_config(NacosCofig.data_id, NacosCofig.group), Loader=yaml.FullLoader)
def start_nacos():
global yaml_data, client
client.add_config_watcher(NacosCofig.data_id, NacosCofig.group, _modify_config_cb)
def _modify_config_cb(config):
global yaml_data
yaml_data = yaml.load(client.get_config(NacosCofig.data_id, NacosCofig.group), Loader=yaml.FullLoader)
print(yaml_data)
def service_register():
global client
client.add_naming_instance(NacosCofig.server_name, NacosCofig.server_ip, NacosCofig.server_port,
ephemeral=False, group_name=NacosCofig.group, heartbeat_interval=5)
if name == 'main':
start_nacos()
service_register()
app.run(debug=False, port=7004, host="0.0.0.0")
before:


after: