WebFaction
Community site: login faq
2
2

Hi,

I running:

Django (trunk)/mod_wsgi (3.3)/Python (2.7)

At my work, we can $touch the .wsgi file and that acts like an Apache restart.

When I touch the .wsgi file for my project, nothing reloads; I still have to restart Apache in order to see changes.

Can I setup my project's .wsgi file to reload my django stuff when I touch it?

Thanks so much!

Cheers, Micky

asked 28 Feb '12, 14:56

mhulse
411617
accept rate: 0%


According to the mod_wsgi docs, code reloading generally works better when using mod_wsgi in daemon mode. Our Django trunk installer currently sets things up in embedded mode, so if your code isn't reloading, then you're probably bumping into this bit:

Do note though that this script reloading mechanism is not intended as a general purpose code reloading mechanism. Only the script file itself is reloaded, no other Python modules are reloaded. This means that if modifying normal Python code files which are used by your WSGI application, you will need to trigger a restart of Apache. For example, if you are using Django in embedded mode and needed to change your 'settings.py' file, you would still need to restart Apache.

We're going to change our Django trunk installer so that it sets things up in daemon mode, so new apps will be easier to work with. I can't say how soon that will happen, so if you want to want to switch to daemon mode now, there are two ways to go about it:

  • You can create a Django 1.3.1 (mod_wsgi 3.3/Python 2.7) app via our control panel, update those libraries to the latest trunk, and re-deploy your code under that app, or...
  • You can update your existing httpd.conf to include the following directives, just before the WSGIScriptAlias directive (be sure to change the username, app name, and any other parts that are specific to your app, and restart Apache after making the changes):
    WSGIDaemonProcess your_app processes=2 threads=12 python-path=/home/your_username/webapps/your_app:/home/your_username/webapps/your_app/lib/python2.7
    WSGIProcessGroup your_app
    WSGIRestrictEmbedded On
    WSGILazyInitialization On

I recommend that you take the first option, since that installer will set up Apache with the worker MPM and will be a bit more frugal with RAM usage.

Hope that helps!

permanent link

answered 29 Feb '12, 15:47

seanf
12.2k41836
accept rate: 37%

Thanks Sean! I really appreciate the reply and the infromative infomation. I will test this tonight and get back to you with my results. Thanks! :)

(29 Feb '12, 16:18) mhulse

I started with a fresh copy of Django 1.3.1 and everything is working perfectly now! Touching my wsgi file is just like a restart. Thanks again Sean and John, you guys rock!

(21 Mar '12, 23:21) mhulse

You should be able to just touch the wsgi file and have changes to python code update.

Some simple things to check,

Are you using the right .wsgi file? Some projects have more than one located in the deployment directory depending on what was left over from deployment. To double check use the path defined in the apache2/conf/httpd.conf file.

Are the changes related to python and the django *.py files or another resource like an external binary or API?

You may also submit a support ticket if you would like us to test in real-time.

permanent link

answered 28 Feb '12, 18:05

johns
5.4k312
accept rate: 23%

Thank you John! Very helpful! I need to do some testing and I will get back to you asap with my results. Much appreciated!

(29 Feb '12, 00:35) mhulse

You're welcome.

(29 Feb '12, 00:59) johns

Hi John,

Unfortunately, it appears as though touching my project's wsgi file does not work for me. :(

I must have things setup wrong.

Would it be helpful for me to post my wsgi/conf files?

The type of changes I am looking for are, for example, if I clear my model and do a syncdb (for example).

IIRC (from last night) some changes happen instantly (like modifying admin.py), but others changes to django .py files I have to restart (touching does the wsgi does nothing).

What would be a good way to test if $ touch is working? Perhaps I'm just doing things that require a full apache restart?

I am probably just doing things wrong. :D

(29 Feb '12, 12:52) mhulse
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×225
×62
×24
×1

question asked: 28 Feb '12, 14:56

question was seen: 17,793 times

last updated: 21 Mar '12, 23:21

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM