views:

243

answers:

4

Hi folks,

I'm noticing that my django development server (version 1.1.1) on my local windows7 machine is using a lot of CPU (~30%, according to task manager's python.exe entry), even in idle state, i.e. no request coming in/going out. Is there an established way of analysing what might be responsible for this?

Thanks!

Martin

+1  A: 

Hit Control-C and crash the process. It will probably crash somewhere that it's spending a lot of time.

Or you could use a profiler.

wisty
You might think this is a joke, but seriously, this can be a fast way to find out where your program is spending a lot of time. Beyond this fast-and-brutal approach, use a profiler.
steveha
A: 

http://docs.python.org/library/profile.html

That's the standard approach.

S.Lott
A: 

The standard approach is to use a profiler. If, for some reason you can't (such as there is no profiler available in the Apache modpython that is running your Django) your best bet might be simply to instrument your program with logging. Watch the messages from your program, and see what you can learn from them.

If you see a message "Entering CalculateFoo()" and then five seconds later "Exiting CalculateFoo()" that's a major clue there. Or if one particular function keeps printing over and over and over.

Here's a short discussion of Python logging.

http://stackoverflow.com/questions/1623039/python-debugging-tips/1623243#1623243

EDIT: I just noticed that you specifically said this is on your Windows 7 desktop. So, use a profiler. But I'll leave this answer up to cover the general case.

steveha
+2  A: 

FWIW, you should do the profiling, but when you do I'll bet you find that the answer is "polling for changes to your files so it can auto-reload." You might do a quick test with "python manage.py runserver --noreload" and see how that affects the CPU usage.

Carl Meyer
this did the magic - cpu usage in idle state dropepd to 0%...
Hoff