sanic: Triggering a worker reload does not take the code change into consideration
Describe the bug
Changing the code - like the response returned by a view - should be updated when the Sanic instance is reloaded (triggered either via the CLI --trigger-reload or via app.m.restart("__ALL_PROCESSES__").
Right now, it doesn’t seems to be the case
Code snippet
from sanic import Sanic
from sanic.response import text
app = Sanic('Test')
@app.get('/reload')
async def re(request):
request.app.m.restart("__ALL_PROCESSES__")
return text('Restart triggered')
@app.get('/')
async def index(request):
return text('Hello world')
if __name__ == '__main__':
app.run(host='127.0.0.1', port=1337, access_log=True, debug=True)
Expected behavior
- Run the above code
- Go to “http://127.0.0.1:1337/”
- See the data : “Hello world”
- Change the code and replace “Hello world” by something else
- Go to “http://127.0.0.1:1337/reload”
- The console shows that the server was restarted
- Go back to “http://127.0.0.1:1337/”
- The text displayed is still “Hello world”, not the new one.
(Restarting the server via the command line sanic --trigger-reload app:app has the same behavior.
Environment (please complete the following information):
- Sanic Version: 22.9.0
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 20 (20 by maintainers)
Correct. This needs to be decided up front. My point earlier would be to always select
spawnifALLOW_RELOAD="always"or something like that. In the meantime, you could monkeypatch it so that auto-reload is off, but you can manually reload with spawn context: