In my Virtualenv created a “Hello, World!” webapplication to test Gunicorn.
This is the code that I am using:
def app(environ, start_response):
data = "Hello, World!\n"
start_response("200 OK", [
("Content-Type", "text/plain"),
("Content-Length", str(len(data)))
])
return iter([data])
When I visit (http://127.0.0.1:8000) it clearly outputs: “Hello, World!” as it should do. But once I change the data string to: data = "This is an edit!" and refresh the browser, it still displays: “Hello, World!”. My conclusion; It looks like I have to restart Gunicorn each time after I changed something in my code, which is a real pain in the butt while working in a development environment.
Is there a way to fix this?
When I perform a cat command it displays the code correctly:
(web)sl@cker:~/Envs/web/myapp$ cat myapp.py
def app(environ, start_response):
data = "This is an edit!"
start_response("200 OK", [
("Content-Type", "text/plain"),
("Content-Length", str(len(data)))
])
return iter([data])
I used this command to start the server: gunicorn -w 4 myapp:app
You need to reload gunicorn because its still holding on to myapp.pyc which is no longer the same as myapp.py.
See here for how modwsgi does it, you might find your answer there.