sanic-org / sanic

Accelerate your web app development | Build fast. Run fast.
https://sanic.dev
MIT License
18k stars 1.54k forks source link

dynamic update blueprint #2991

Open amoxuk opened 1 month ago

amoxuk commented 1 month ago

Is there an existing issue for this?

Describe the bug

some package in my folder, I want add new package in the folder at sanic running.

@app.get('xx') async def reload(rq): for folder in os.listdir('somefolder'): pkg = importlib.import_module(folder) _lib.append(pkg.app) bp = Bleprint.group(*_lib,url_prefix='/someurl') app.router.reset() app.blueprint(bp)

reload success but use the url throw error. Nonetype object is not callable in sanic router

Code snippet

No response

Expected Behavior

No response

How do you run Sanic?

As a script (app.run or Sanic.serve)

Operating System

Linux

Sanic Version

22.12.0

Additional context

No response

amoxuk commented 1 month ago

add app.finalize() to solve this problem.

But here is a new problem.

After reload, I can request the blueprint's url many times if I refresh the browser quickly, but it returns 404 after the sanic logs 'KeepAlive Timeout,Closing cojnextion.'.

It looks like I reload a temp variable of 'app'.

How to reload the gloable app?