[vlma-devel] commit: Ability to lock the "restart" action. (Adrien Grand )

git version control git at videolan.org
Tue Mar 10 02:22:58 CET 2009


vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Sun Mar  8 03:10:54 2009 +0100| [13e029a8bf01b840b69fa0f3ecd7cd5f7d7022ae] | committer: Adrien Grand 

Ability to lock the "restart" action.

> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=13e029a8bf01b840b69fa0f3ecd7cd5f7d7022ae
---

 vlma-watchdog/src/vlc.py |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/vlma-watchdog/src/vlc.py b/vlma-watchdog/src/vlc.py
index 6fb2f53..0490007 100644
--- a/vlma-watchdog/src/vlc.py
+++ b/vlma-watchdog/src/vlc.py
@@ -141,6 +141,7 @@ class VLC:
   def __init__(self):
     self.logger = logging.getLogger("VLC")
     self.runner = None
+    self.__suspended = False
     self.__lock = threading.RLock()
     self.__log_queue = []
     self.__log_queue_lock = threading.RLock()
@@ -151,7 +152,9 @@ class VLC:
 
   def start(self):
     self.__lock.acquire()
-    if not self.runner is None and self.runner.isAlive():
+    if self.__suspended:
+      logger.error("VLC is currently suspended, won't start")
+    elif not self.runner is None and self.runner.isAlive():
       logger.error("Cannot start VLC, another instance is still running.")
       logger.info("Please stop VLC first")
     else:
@@ -212,6 +215,12 @@ class VLC:
     time.sleep(1)
     self.start()
 
+  def setSuspended(self, suspended):
+    self.__lock.acquire()
+    self.__suspended = suspended
+    self.__lock.release()
+
+
 class Monitor(threading.Thread):
 
   def __init__(self, vlc):
@@ -226,6 +235,8 @@ class Monitor(threading.Thread):
       cpuLoad = self.getCpuLoad()
       if cpuLoad >= conf.CPU_LOAD_THRESHOLD:
         logger.warn("CPU load is %f, VLC restart triggered", cpuLoad)
+        # Prevent someone from restarting VLC while the load is too high
+        self.vlc.setSuspended(True)
         self.vlc.stop()
         # Because the load won't go down in one millisecond
         logger.info("Waiting for the load to decrease")
@@ -233,6 +244,7 @@ class Monitor(threading.Thread):
           time.sleep(5)
           if self.getCpuLoad() < conf.CPU_LOAD_THRESHOLD:
             break
+        self.vlc.setSuspended(False)
         self.vlc.start()
         continue
       vlcCpu = self.getVlcCpu()



More information about the vlma-devel mailing list