pythondjangowindowsdaemonwaitress

Django waitress- How to run it in Daemon Mode


I've a django application with waitress (gunicorn doesn't work on windows) to serve it. Because its production code and its based on windows 2012 server. But I want the django application to run in daemon mode is it possible?

Daemon mode - app running without command prompt opening/visible also it'll be helpful to open the shell without closing the server. AutoStart if for some reason system has to restart.

Note:

Limitations: The project cannot be moved to UNIX based system. Third-Party applications like any .exe file cannot be used. You cannot use Docker as it consumes a lot of space.


Solution

  • For production:
    create a file server.py at same level as manage.py and add following:

    from waitress import serve
        
    from myapp.wsgi import application
        
    if __name__ == '__main__':
        serve(application, port='8000')
    

    Start-Process python -NoNewWindow -ArgumentList "server.py"
    You can close the terminal after that and it still runs.
    If you later want to stop, you have to do with Get-Process and then TaskKill
    Running with CMD:

    START "myapp" /B python server.py
    Running in cmd