0

I've modified a .py file on a production server and the changes are not being applied. At first I thought this was because the associated .pyc file was not being updated. So I deleted the .pyc file and tested hoping the .py file would compile into a new .pyc file. The applications behavior did not update and a new .pyc file was not created. This was done based off a previous question.

How is it that the script is executing without generating a new .pyc file? Here are the two files in question:

-rw-r--r--  1 ubuntu ubuntu  47872 Jul 13 04:39 admin_email.py
-rw-r--r--  1 root   root    48212 Feb 10 03:12 admin_email.pyc

admin_email.pyc has been deleted. Only admin_email.py remains on there server.

Here is the code that is executing the script that has been changed:

from xxx.admin_email import send_email_admins
...
g = lambda x, y, z: send_email_admins(x, y, z)
...
threading.Thread(target=g, args=(order_id, request.user.email, form.cleaned_data)).start()

The application is being served with gunicorn + nginx.

Any ideas on what the issue is? Why is a new .pyc file being created? More importantly why is the applications behavior not being updated?

Community
  • 1
  • 1
evanill80
  • 157
  • 2
  • 11

1 Answers1

1

Im assuming you're suing wsgi or fcgi - most probably on apache or nginx

With wsgi - normally apache will cache your django for you.

So, you need to tell apache/nginx/server-provider that your django code has changed. The way you do this is by changing the "last edited" meta information of your .wsgi file. So, you simple do touch /path/to/django.wsgi and it will normally work.

If you use fcgi, the same thing applies.

AbdealiLoKo
  • 3,261
  • 2
  • 20
  • 36
  • OK I changed the last edit of `/.../wsgi.py` by _touching_ it. A new `admin_email.pyc` still has not been created. – evanill80 Jul 13 '15 at 21:15
  • Well, has the admin_email.py code been used in anyway after the wsgi.py was edited ?Is it being imported at all ? A good way of testing this would be to do something like `a = open("tempfile.txt", "w"); a.close()` and checking if the tempfile was created. If it is not created means that the file isnt really being imported at all ... and hence no .pyc - This could be because there's an error in some module before it is getting imported? – AbdealiLoKo Jul 13 '15 at 21:22
  • Yes it is being imported. In the above code snippet: `from xxx.admin_email import send_email_admins` – evanill80 Jul 13 '15 at 21:55
  • If you've changed lots of files - it's easier to do `sudo service apache2 reload` (if you've using apache2) - ah, but i see in an above comment you're using gunicorn + nginx - so it'll be a different incantation! – stephendwolff Jul 14 '15 at 08:49
  • Yes, if someone could please advise on how to successfully reload or restart a server running gunicorn + nginx it would be awesome. I did not create this application and there was no documentation created so Im not too sure how to restart or reload the server. Since this is a production server Im worried I will not be able to restart if I do something incorrectly. – evanill80 Jul 14 '15 at 21:22