Commit 0f26522f authored by Gabriel Monnerat's avatar Gabriel Monnerat

clean up the code and add NoSuchProcess exception. This exception is raised...

clean up the code and add NoSuchProcess exception. This exception is raised when a process with a certain PID doesn't or no longer exists (zombie)

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@41912 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1812a70f
...@@ -49,15 +49,17 @@ class MonitorMemory(Monitor, Process): ...@@ -49,15 +49,17 @@ class MonitorMemory(Monitor, Process):
def get_memory_usage(self): def get_memory_usage(self):
try: try:
if not hasattr(self, 'process'): if not hasattr(self, 'process') or \
self.create_process() self.process.pid != int(self.openoffice.pid()):
elif self.process.pid != int(self.openoffice.pid()):
self.create_process() self.create_process()
return sum(self.process.get_memory_info()) / (1024 * 1024)
except TypeError: except TypeError:
logger.debug("OpenOffice is stopped") logger.debug("OpenOffice is stopped")
return 0 return 0
# convert bytes to MB except psutil.NoSuchProcess, e:
return sum(self.process.get_memory_info()) / (1024 * 1024) # Exception raised when a process with a certain PID doesn't or no longer
# exists (zombie).
return 0
def run(self): def run(self):
"""Is called by start function. this function is responsible for """Is called by start function. this function is responsible for
......
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