why my django site doesn't create .pyc file?

1,006 views
Skip to first unread message

pength

unread,
Jun 9, 2008, 6:25:04 AM6/9/08
to Django users
I have justed built my site on slicehost. Alhough my site is running
properly, I found if I update any file (.py file, of course), it
never recreate the .pyc file. Actually, if I delete any .pyc file,
then it will never appear.

I think there's something wrong with my site config, can anyone give
me any hint?

I am using nginx as front proxy server and static file server, apache2
and mod_python as backend.

Thanks!

Valts Mazurs

unread,
Jun 9, 2008, 7:39:26 AM6/9/08
to django...@googlegroups.com
Hello,

Check if web server process has enough privileges to write in the directories containing .py files.

Regards,
Valts.

pength

unread,
Jun 9, 2008, 9:40:17 AM6/9/08
to Django users
Thanks a lot !

I changed the user information in apache2's conf file, and now it's
OK!

I think this way, apache could be a little more faster. Am I right?

Scott Moonen

unread,
Jun 9, 2008, 9:50:01 AM6/9/08
to django...@googlegroups.com
I think this way, apache could be a little more faster. Am I right?

I don't think it will be faster.  Django normally runs as a long-standing process (either inside Apache or as a standalone process, depending on the deployment model you've chosen).  So, unlike ordinary CGI scripts, your Python bytecode will not need to be generated except for the very first time that your code is loaded.  Once it's up and running it will already be in memory so it won't need to be reinterpreted.

I personally don't think the trade-off is worth it here.  You're giving Apache write access to your source code (which may not be much of a security risk relative to other things like the fact that Apache has access to your database, but it is definitely a blurring of privilege boundaries), and you're not getting any long-running performance benefit from it; only a slight initial load benefit.


  -- Scott
--
http://scott.andstuff.org/ | http://truthadorned.org/

Tim Chase

unread,
Jun 9, 2008, 10:03:23 AM6/9/08
to django...@googlegroups.com
>> I think this way, apache could be a little more faster. Am I
>> right?
>
> I don't think it will be faster. Django normally runs as a
> long-standing process (either inside Apache or as a standalone
> process, depending on the deployment model you've chosen).
> So, unlike ordinary CGI scripts, your Python bytecode will not
> need to be generated except for the very first time that your
> code is loaded. Once it's up and running it will already be
> in memory so it won't need to be reinterpreted.

If you want, you can pre-compile everything as described at

http://effbot.org/pyfaq/how-do-i-create-a-pyc-file.htm

which shows you can issue

bash$ cd ~/code
bash$ python -m compileall .
[output]

which will compile each .py file into a corresponding .pyc file
within the current directory and subdirectories. I believe the
Debian variants (others may as well) do this in the system
directories upon installation so users don't have to recompile
all the system libraries.

The time saved is minimal, but there's no harm in preemptively
compiling your files.

-tim

pength

unread,
Jun 9, 2008, 11:29:54 PM6/9/08
to Django users
Tim and Scott, thank you very much!

Jeff Anderson

unread,
Jun 9, 2008, 11:33:47 PM6/9/08
to django...@googlegroups.com
Scott Moonen wrote:
>> I think this way, apache could be a little more faster. Am I right?
>>
>>
>
> I don't think it will be faster. Django normally runs as a long-standing
> process (either inside Apache or as a standalone process, depending on the
> deployment model you've chosen). So, unlike ordinary CGI scripts, your
> Python bytecode will not need to be generated except for the very first time
> that your code is loaded. Once it's up and running it will already be in
> memory so it won't need to be reinterpreted.
>
When I first noticed that mod_python didn't seem to spit out .pyc files,
I figured that this was a "feature" because of its one-time loading
nature. I kind of liked the concept because .pyc files seem like clutter
sometimes. Good to know that my assumption was wrong. I'm going to keep
my permissions the way that they are. :)

signature.asc
Reply all
Reply to author
Forward
0 new messages