[Checkins] SVN: zdaemon/trunk/src/zdaemon/ Bug fixed: detection of daemon startup and shutdown was broken

Florent Xicluna laxyf at yahoo.fr
Sun Dec 2 12:08:49 EST 2007


Log message for revision 82079:
  Bug fixed: detection of daemon startup and shutdown was broken
  

Changed:
  U   zdaemon/trunk/src/zdaemon/README.txt
  U   zdaemon/trunk/src/zdaemon/tests/tests.py
  U   zdaemon/trunk/src/zdaemon/zdctl.py

-=-
Modified: zdaemon/trunk/src/zdaemon/README.txt
===================================================================
--- zdaemon/trunk/src/zdaemon/README.txt	2007-12-02 14:03:30 UTC (rev 82078)
+++ zdaemon/trunk/src/zdaemon/README.txt	2007-12-02 17:08:48 UTC (rev 82079)
@@ -53,10 +53,11 @@
 daemon :)
 
     >>> system("./zdaemon -p 'sleep 100' start")
-    . daemon process started, pid=819
+    . .
+    daemon process started, pid=819
 
 This ran the sleep deamon.  We can check whether it ran with the
-status command:  
+status command:
 
     >>> system("./zdaemon -p 'sleep 100' status")
     program running; pid=819
@@ -64,6 +65,7 @@
 We can stop it with the stop command:
 
     >>> system("./zdaemon -p 'sleep 100' stop")
+    . .
     daemon process stopped
 
     >>> system("./zdaemon -p 'sleep 100' status")
@@ -82,7 +84,8 @@
 Now, we can run with the -C option to read the configuration file:
 
     >>> system("./zdaemon -Cconf start")
-    . daemon process started, pid=1136
+    . .
+    daemon process started, pid=1136
 
 If we list the directory:
 
@@ -96,6 +99,7 @@
 where this goes.
 
     >>> system("./zdaemon -Cconf stop")
+    . .
     daemon process stopped
 
     >>> open('conf', 'w').write(
@@ -108,7 +112,8 @@
 
 
     >>> system("./zdaemon -Cconf start")
-    . daemon process started, pid=1139
+    . .
+    daemon process started, pid=1139
 
     >>> system("ls")
     conf
@@ -119,6 +124,7 @@
     True
 
     >>> system("./zdaemon -Cconf stop")
+    . .
     daemon process stopped
 
 In the example, we included a command-line argument in the program
@@ -133,12 +139,14 @@
     ... ''')
 
     >>> system("./zdaemon -Cconf start 100")
-    . daemon process started, pid=1149
+    . .
+    daemon process started, pid=1149
 
     >>> system("./zdaemon -Cconf status")
     program running; pid=1149
 
     >>> system("./zdaemon -Cconf stop")
+    . .
     daemon process stopped
 
 Environment Variables
@@ -182,7 +190,7 @@
 controlling terminal.  It can optionally redirect the output to
 standard error and standard output to a file.  This is done with the
 transcript option.  This is, of course, useful for logging output from
-long-running applications.  
+long-running applications.
 
 Let's look at an example. We'll have a long-running process that
 simple tails a data file:
@@ -200,7 +208,8 @@
     ... ''')
 
     >>> system("./zdaemon -Cconf start")
-    . daemon process started, pid=7963
+    . .
+    daemon process started, pid=7963
 
 .. Wait a little bit to make sure tail has a chance to work
 
@@ -211,7 +220,7 @@
 
     >>> open('log').read()
     'rec 1\n'
-    
+
 We can rotate the transcript log by renaming it and telling zdaemon to
 reopen it:
 

Modified: zdaemon/trunk/src/zdaemon/tests/tests.py
===================================================================
--- zdaemon/trunk/src/zdaemon/tests/tests.py	2007-12-02 14:03:30 UTC (rev 82078)
+++ zdaemon/trunk/src/zdaemon/tests/tests.py	2007-12-02 17:08:48 UTC (rev 82079)
@@ -31,7 +31,7 @@
 def make_sure_non_daemon_mode_doesnt_hang_when_program_exits():
     """
     The whole awhile bit that waits for a program to start
-    whouldn't be used on non-daemopn mode.
+    whouldn't be used on non-daemon mode.
 
     >>> open('conf', 'w').write(
     ... '''
@@ -58,14 +58,14 @@
     ... ''')
 
     >>> system("./zdaemon -Cconf start")
-    . . 
-    Daemon manager not running.
+    . .
+    daemon manager not running
 
     """
-    
+
 def allow_duplicate_arguments():
     """
-    
+
 Wrapper scripts will often embed configuration arguments. This could
 cause a problem when zdaemon reinvokes itself, passing it's own set of
 configuration arguments.  To deal with this, we'll allow duplicate
@@ -79,9 +79,11 @@
     ... ''')
 
     >>> system("./zdaemon -Cconf -Cconf -Cconf start")
-    . daemon process started, pid=21446
+    . .
+    daemon process started, pid=21446
 
     >>> system("./zdaemon -Cconf -Cconf -Cconf stop")
+    . .
     daemon process stopped
 
 """
@@ -127,6 +129,7 @@
             setUp=setUp, tearDown=tearDown,
             checker=renormalizing.RENormalizing([
                 (re.compile('pid=\d+'), 'pid=NNN'),
+                (re.compile('(\. )+\.?'), '<BLANKLINE>'),
                 ])
         ),
         doctest.DocFileSuite(
@@ -134,6 +137,7 @@
             setUp=setUp, tearDown=tearDown,
             checker=renormalizing.RENormalizing([
                 (re.compile('pid=\d+'), 'pid=NNN'),
+                (re.compile('(\. )+\.?'), '<BLANKLINE>'),
                 (re.compile('^env\n((?:.*\n)+)$'), checkenv),
                 ])
         ),

Modified: zdaemon/trunk/src/zdaemon/zdctl.py
===================================================================
--- zdaemon/trunk/src/zdaemon/zdctl.py	2007-12-02 14:03:30 UTC (rev 82078)
+++ zdaemon/trunk/src/zdaemon/zdctl.py	2007-12-02 17:08:48 UTC (rev 82079)
@@ -128,7 +128,7 @@
             if m:
                 s = m.group(1)
                 args = eval(s, {"__builtins__": {}})
-                program = self.options.program 
+                program = self.options.program
                 if args[:len(program)] != program:
                     print "WARNING! zdrun is managing a different program!"
                     print "our program   =", program
@@ -194,28 +194,26 @@
         return resp
 
     def awhile(self, cond, msg):
-        n = 0
-        was_running = True
+        was_running = False
         try:
-            if self.get_status():
-                was_running = True
-                
-            while not cond():
+            for n in range(10):
+                if self.get_status(): # running?
+                    was_running = True
+                elif was_running: # no longer running?
+                    break
+                if cond(): # condition fulfilled?
+                    break
                 sys.stdout.write(". ")
                 sys.stdout.flush()
                 time.sleep(1)
-                n += 1
-                if self.get_status():
-                    was_running = True
-                elif was_running or n > 10:
-                    print "\nDaemon manager not running."
-                    return
 
         except KeyboardInterrupt:
             print "^C"
-        else:
-            print msg % self.__dict__
 
+        if not cond():
+            msg = "daemon manager not running"
+        print "\n" + msg % self.__dict__
+
     def help_help(self):
         print "help          -- Print a list of available actions."
         print "help <action> -- Print help for <action>."
@@ -235,7 +233,7 @@
             else:
                 args = [self.options.python, sys.argv[0]]
                 os.environ['DAEMON_MANAGER_MODE'] = '1'
-                
+
             args += self._get_override("-S", "schemafile")
             args += self._get_override("-C", "configfile")
             args += self._get_override("-b", "backofflimit")
@@ -619,7 +617,7 @@
     if os.environ.get('DAEMON_MANAGER_MODE'):
         import zdaemon.zdrun
         return zdaemon.zdrun.main(args)
-        
+
     if options is None:
         options = ZDCtlOptions()
     options.realize(args)



More information about the Checkins mailing list