dynamic update blueprint
amoxuk opened this issue · 2 comments
Is there an existing issue for this?
- I have searched the existing issues
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
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?