If using mod_wsgi daemon mode, what happens when the script file is changed is different to what happens in embedded mode. In daemon mode, if the script file changed, rather than just the script file being reloaded, the daemon process which contains the application will be shutdown and restarted automatically.
Detection of the change in the script file will occur at the time of the first request to arrive after the change has been made. The way that the restart is performed does not affect the handling of the request, with it still being processed once the daemon process has been restarted.
In the case of there being multiple daemon processes in the process group, then a cascade effect will occur, with successive processes being restarted until the request is again routed to one of the newly restarted processes.
In this way, restarting of a WSGI application when a change has been made to the code is a simple matter of touching the script file if daemon mode is being used. Any daemon processes will then automatically restart without the need to restart the whole of Apache.
So, if you are using Django in daemon mode and needed to change your 'settings.py' file, once you have made the required change, also touch the script file containing the WSGI application entry point. Having done that, on the next request the process will be restarted and your Django application reloaded.
Also, while I think the idea is neat, I'm not sure how useful it will be.
Most people do not change the files directly, instead they have a deployment
procedure that also includes restarting workers. I guess you are considering this
mostly for development?
Also, while I think the idea is neat, I'm not sure how useful it will be.
Most people do not change the files directly, instead they have a deployment
procedure that also includes restarting workers. I guess you are considering this
mostly for development?The point is that in production we would NOT have to restart workers. This means we would NOT have to worry about safely shutting down workers and existing tasks. This would be great for those tasks that are non trivial. We do NOT have to wait until the tasks complete, nor worry about if the tasks is killed halfway when we shutdown a worker having to RESUME.
Thus, it makes great sense not only for development, though for PRODUCTION.
You would still have to worry about workers restarting, and that they do so safely and that currently executing tasks tasks complete in a timely manner.
The only difference here is that it would happen on any file change,
does that really make it better?
The only way to solve that is to have a dedicated
process that monitors the worker.