question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Triggering a worker reload does not take the code change into consideration

See original GitHub issue

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

  1. Run the above code
  2. Go to “http://127.0.0.1:1337/
  3. See the data : “Hello world”
  4. Change the code and replace “Hello world” by something else
  5. Go to “http://127.0.0.1:1337/reload
  6. The console shows that the server was restarted
  7. Go back to “http://127.0.0.1:1337/
  8. 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:closed
  • Created a year ago
  • Comments:19 (19 by maintainers)

github_iconTop GitHub Comments

1reaction
ahopkinscommented, Oct 2, 2022

(Except if the spawn vs fork is defined at the initial run, and cannot be changed after that?)

Correct. This needs to be decided up front. My point earlier would be to always select spawn if ALLOW_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:

from sanic import Sanic

Sanic._get_context = lambda *_: get_context("spawn")
0reactions
cnicodemecommented, Oct 10, 2022

In that case, I think we can close this ticket, it is working fine and resolved for me.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found