Commit 749d636c authored by sumpfralle's avatar sumpfralle

improve stability of "get_statistics"


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@765 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent f4dbc091
...@@ -463,16 +463,24 @@ class ProcessStatistics(object): ...@@ -463,16 +463,24 @@ class ProcessStatistics(object):
self._refresh_workers() self._refresh_workers()
now = time.time() now = time.time()
result = [] result = []
for key in self.workers: # Cache the key list instead of iterating it - otherwise a
if key in self.processes: # "RuntimeError: dictionary changed size during iteration" may occour.
all_keys = self.workers.keys()
for key in all_keys:
try:
one_process = self.processes[key] one_process = self.processes[key]
last_notification = int(now - self.workers[key]) last_notification = int(now - self.workers[key])
num_of_tasks = one_process.process_count num_of_tasks = one_process.process_count
process_time = one_process.process_time process_time = one_process.process_time
avg_process_time = process_time / num_of_tasks # avoid divide-by-zero
avg_transfer_time = one_process.transfer_time / num_of_tasks avg_process_time = process_time / max(1, num_of_tasks)
avg_transfer_time = one_process.transfer_time \
/ max(1, num_of_tasks)
result.append((key, last_notification, num_of_tasks, result.append((key, last_notification, num_of_tasks,
process_time, avg_process_time, avg_transfer_time)) process_time, avg_process_time, avg_transfer_time))
except KeyError:
# no data available yet or the item was removed meanwhile
pass
return result return result
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment