[Erp5-report] r38985 gabriel - in /erp5/trunk/utils/cloudooo/cloudooo: monitor/ tests/
nobody at svn.erp5.org
nobody at svn.erp5.org
Fri Oct 8 00:43:50 CEST 2010
Author: gabriel
Date: Fri Oct 8 00:43:50 2010
New Revision: 38985
URL: http://svn.erp5.org?rev=38985&view=rev
Log:
- Refactor to use Process instead of Thread. processes are more reliable to stop it.
- clean up the tests
Modified:
erp5/trunk/utils/cloudooo/cloudooo/monitor/memory.py
erp5/trunk/utils/cloudooo/cloudooo/tests/testMonitorInit.py
erp5/trunk/utils/cloudooo/cloudooo/tests/testMonitorMemory.py
Modified: erp5/trunk/utils/cloudooo/cloudooo/monitor/memory.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/monitor/memory.py?rev=38985&r1=38984&r2=38985&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/monitor/memory.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/monitor/memory.py [utf8] Fri Oct 8 00:43:50 2010
@@ -27,12 +27,12 @@
##############################################################################
from cloudooo.monitor.monitor import Monitor
-from threading import Thread
-from psutil import Process
+from multiprocessing import Process
+import psutil
from cloudooo.utils import logger
from time import sleep
-class MonitorMemory(Monitor, Thread):
+class MonitorMemory(Monitor, Process):
"""Usefull to control the memory and does not allow use it unnecessarily"""
def __init__(self, openoffice, interval, limit_memory_usage):
@@ -40,11 +40,11 @@ class MonitorMemory(Monitor, Thread):
and ILockable, the limit of memory usage that the openoffice can use and the
interval to check the object."""
Monitor.__init__(self, openoffice, interval)
- Thread.__init__(self)
+ Process.__init__(self)
self.limit = limit_memory_usage
def create_process(self):
- self.process = Process(int(self.openoffice.pid()))
+ self.process = psutil.Process(int(self.openoffice.pid()))
def get_memory_usage(self):
try:
@@ -55,7 +55,7 @@ class MonitorMemory(Monitor, Thread):
except TypeError:
logger.debug("OpenOffice is stopped")
return 0
- # convert bytes to GB
+ # convert bytes to MB
return sum(self.process.get_memory_info())/(1024*1024)
def run(self):
@@ -71,3 +71,7 @@ class MonitorMemory(Monitor, Thread):
self.openoffice.stop()
sleep(self.interval)
logger.debug("Stop MonitorMemory")
+
+ def terminate(self):
+ Monitor.terminate(self)
+ Process.terminate(self)
Modified: erp5/trunk/utils/cloudooo/cloudooo/tests/testMonitorInit.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/tests/testMonitorInit.py?rev=38985&r1=38984&r2=38985&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/tests/testMonitorInit.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/tests/testMonitorInit.py [utf8] Fri Oct 8 00:43:50 2010
@@ -54,18 +54,20 @@ class TestMonitorInit(cloudoooTestCase):
def testMonitorLoadOnlyMonitorRequest(self):
"""Check if the monitors are started"""
cloudooo.monitor.load(self.load_config)
- self.assertEquals(isinstance(cloudooo.monitor.monitor_request, MonitorRequest),
- True)
- self.assertEquals(cloudooo.monitor.monitor_memory, None)
-
+ self.assertEquals(isinstance(cloudooo.monitor.monitor_request,
+ MonitorRequest),
+ True)
+
def testMonitorLoadMonitorMemory(self):
"""Check if the MemoryMemory is started"""
self.load_config['enable_memory_monitor'] = True
cloudooo.monitor.load(self.load_config)
- self.assertEquals(isinstance(cloudooo.monitor.monitor_request, MonitorRequest),
- True)
- self.assertEquals(isinstance(cloudooo.monitor.monitor_memory, MonitorMemory),
- True)
+ self.assertEquals(isinstance(cloudooo.monitor.monitor_request,
+ MonitorRequest),
+ True)
+ self.assertEquals(isinstance(cloudooo.monitor.monitor_memory,
+ MonitorMemory),
+ True)
def test_suite():
return make_suite(TestMonitorInit)
Modified: erp5/trunk/utils/cloudooo/cloudooo/tests/testMonitorMemory.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/tests/testMonitorMemory.py?rev=38985&r1=38984&r2=38985&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/tests/testMonitorMemory.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/tests/testMonitorMemory.py [utf8] Fri Oct 8 00:43:50 2010
@@ -38,6 +38,8 @@ class TestMonitorMemory(unittest.TestCas
"""Test case to see if the MonitorMemory is properly managing the
openoffice."""
+ interval = 3
+
def setUp(self):
if not openoffice.status():
openoffice.start()
@@ -56,7 +58,7 @@ class TestMonitorMemory(unittest.TestCas
try:
self.monitor = MonitorMemory(openoffice, 1, 1000)
self.monitor.start()
- sleep(2)
+ sleep(6)
self.assertEquals(openoffice.status(), True)
finally:
self.monitor.terminate()
@@ -67,7 +69,7 @@ class TestMonitorMemory(unittest.TestCas
try:
self.monitor = MonitorMemory(openoffice, 2, 10)
self.monitor.start()
- sleep(3)
+ sleep(self.interval)
self.assertEquals(openoffice.status(), False)
finally:
self.monitor.terminate()
@@ -76,9 +78,9 @@ class TestMonitorMemory(unittest.TestCas
"""Tests if the monitor continues to run even with openoffice stopped"""
openoffice.stop()
self.monitor = MonitorMemory(openoffice, 2, 1000)
+ self.monitor.start()
try:
- self.monitor.start()
- sleep(3)
+ sleep(self.interval)
self.assertEquals(self.monitor.is_alive(), True)
finally:
self.monitor.terminate()
More information about the Erp5-report
mailing list