[Erp5-report] r36139 luke - /erp5/trunk/utils/erp5.timmy/src/erp5/timmy/timmy.py

nobody at svn.erp5.org nobody at svn.erp5.org
Wed Jun 9 10:59:46 CEST 2010


Author: luke
Date: Wed Jun  9 10:59:46 2010
New Revision: 36139

URL: http://svn.erp5.org?rev=36139&view=rev
Log:
 - setRunning becomes real class member method
 - add setFinished to flag end of work

Modified:
    erp5/trunk/utils/erp5.timmy/src/erp5/timmy/timmy.py

Modified: erp5/trunk/utils/erp5.timmy/src/erp5/timmy/timmy.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.timmy/src/erp5/timmy/timmy.py?rev=36139&r1=36138&r2=36139&view=diff
==============================================================================
--- erp5/trunk/utils/erp5.timmy/src/erp5/timmy/timmy.py [utf8] (original)
+++ erp5/trunk/utils/erp5.timmy/src/erp5/timmy/timmy.py [utf8] Wed Jun  9 10:59:46 2010
@@ -440,7 +440,7 @@
 
   def run(self):
     try:
-      self.setRunning(True, self.options.pid_file)
+      self.setRunning()
     except:
       # XXX-Luke: If possible it would be nice to send such issue to
       #           master server
@@ -534,7 +534,7 @@
             'ntinue, failed: %s.' % e)
         raise
     finally:
-      self.setRunning(False, self.options.pid_file)
+      self.setFinished(False)
       logging.info('[%s] Timmy finished, invocation time: %.3fs' % (os.getpid(),
         time.time() - self.time_begin))
 
@@ -656,30 +656,32 @@
             str(sys.exc_info()[0]), str(sys.exc_info()[1])))
       raise
 
-  def setRunning(self, value, pid_file):
-    if value:
-      if os.path.exists(pid_file):
-        # Pid file is present
-        logging.warning('Timmy already have the pid file %s' % pid_file)
-        pid = open(pid_file, 'r').readline()
-        # XXX This could use psutil library.
-        if os.path.exists("/proc/%s" % pid):
-          # In case process is present, ignore.
-          logging.critical('A Timmy process is running with pid %s' % pid)
-          sys.exit(1)
-      # Start new process
-      self.write_pid(pid_file)
-    else:
-      os.remove(pid_file)
-
-  def write_pid(self, pid_file):
+  def setRunning(self):
+    if os.path.exists(self.options.pid_file):
+      # Pid file is present
+      logging.warning('Timmy already have the pid file %s' %
+          self.options.pid_file)
+      pid = open(self.options.pid_file, 'r').readline()
+      # XXX This could use psutil library.
+      if os.path.exists("/proc/%s" % pid):
+        # In case process is present, ignore.
+        logging.critical('A Timmy process is running with pid %s' % pid)
+        sys.exit(1)
+    # Start new process
+    self.write_pid()
+
+  def setFinished(self):
+    os.remove(self.options.pid_file)
+
+  def write_pid(self):
     pid = os.getpid()
     try:
-      f = open(pid_file, 'w')
+      f = open(self.options.pid_file, 'w')
       f.write('%s' % pid)
       f.close()
     except (IOError, OSError):
-      logging.critical('Timmy could not write pidfile %s' % pid_file)
+      logging.critical('Timmy could not write pidfile %s' %
+          self.options.pid_file)
       raise
 
   def parseOptions(self):




More information about the Erp5-report mailing list