Triggering a worker reload does not take the code change into consideration
See original GitHub issueDescribe 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
Issue Analytics
- State:
- Created a year ago
- Comments:19 (19 by maintainers)
Top Results From Across the Web
reload does not work for uvicorn.workers.UvicornWorker #2339
I'm having some problems with Uvicorn in which Migrations are loaded on app startup, triggering django.core.exceptions.SynchronousOnlyOperation ...
Read more >service worker not active initially, reload needed to activate
I'm experimenting with service workers, so my scenario is very basic. The problem I'm experiencing is that when I load my page the...
Read more >Handling service worker updates with immediacy
In this case, you should strongly consider offering a reload button on service worker updates, since updates to that HTML won't be recognized ......
Read more >How to Fix the Refresh Button When Using Service Workers
When the v2 Service Worker skips waiting to take control, any v1 tab will automatically refresh, turning it into a v2 tab. UPDATE:...
Read more >The service worker lifecycle - web.dev
If you don't know what it's trying to do and what the benefits are ... Allow a new service worker to get itself...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Correct. This needs to be decided up front. My point earlier would be to always select
spawn
ifALLOW_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:In that case, I think we can close this ticket, it is working fine and resolved for me.