Instead of:
def loop_thru_cpus():
for i in cpuStats:
cpuStats = cpuStats[i]
cpuStats = json.dumps(cpuStats._asdict())
...
i = i+1
Try:
def loop_thru_cpus():
for stat in cpuStats:
stat = json.dumps(stat._asdict())
When you say
for i in cpuStats:
i
takes on values from cpuStats
. i
is not an integer in this case. So i = i+1
makes no sense.
cpuStats = cpuStats[i]
This probably raised an IndexError (since i
is not an integer), but for some reason you are not seeing the exception that was raised.
Also note that you are redefining cpuStats
here, which is probably not what you want to do.
You probably do have indentation errors in your code. Running the code you posted through cat -A
shows tabs (indicated below by ^I
):
try:$
^I $
command = 'put cpu.usr ' + str(currentTime) + " " + str(cpuStats[0]) + "host ="+ thisClient+ "/n"$
...
params = urllib.urlencode({'cpuStats': cpuStats, 'thisClient': 1234})$
...
^I print response.status, response.reason$
$
^I except IndexError:$
break$
You can not mix tabs and spaces an indentation in Python code. Either use one or the other. The PEP8 style guide (and most code you see on the net) uses 4 spaces. Mixing tabs and spaces usually results in an IndentationError, but sometimes you don't get an error and just code that behaves in unexpected ways. So (if using the 4-spaces convention) be careful to use an editor that adds 4 spaces when the tab key is pressed.
Since you are not seeing the IndexError, you may not be seeing the IndentationError that should have been occurred either. How exactly are you running the problem?