nacos-group / nacos-group/nacos-sdk-python
flask项目注册到nacos,一开始没问题.过一会nacos监控那里实例数就没了
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 471
- Forks
- 155
- PR merge metrics
- No merged PRs in 30d
Description
code
import datetime
import logging
import random
from flask import Flask
from pyctuator.pyctuator import Pyctuator
import nacos
# Keep the console clear - configure werkzeug (flask's WSGI web app) not to log the detail of every incoming request
logging.getLogger("werkzeug").setLevel(logging.WARNING)
my_logger = logging.getLogger("example")
app = Flask("Flask Example Server")
@app.route("/")
def hello():
my_logger.debug(f"{datetime.datetime.now()} - {str(random.randint(0, 100))}")
print("Printing to STDOUT")
return "Hello World!"
example_app_address = "192.168.1.2"
example_sba_address = "192.168.1.6"
Pyctuator(
app,
"huiche-ai",
app_url=f"http://{example_app_address}:5000",
pyctuator_endpoint_url=f"http://{example_app_address}:5000/pyctuator",
registration_url=f"http://{example_sba_address}:8764/instances",
app_description="Demonstrate Spring Boot Admin Integration with Flask",
)
def regis_server_to_nacos():
SERVER_ADDRESSES = "192.168.1.6"
NAMESPACE = "public"
# no auth mode
client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE)
# auth mode
# client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE, username="nacos", password="nacos")
# get config
data_id = "nacos.cfg.dataId"
group = "test"
print(client.get_config(data_id, group))
client.add_naming_instance("heiche-ai", "192.168.1.2", "5000")
if __name__ == '__main__':
regis_server_to_nacos()
app.run(port=5000, host="0.0.0.0",debug=True)
- 启动项目,nacos上成功注册

2.过一会

Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with regis_server_to_nacos(), especially client.add_naming_instance(), and compare its registration flow with the subsequent app.run() call. Reproduce the instance disappearing from Nacos, then inspect the registration lifecycle and comment history; done means the Flask instance remains visible after the reported delay.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend, distributed-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100