Commits

Anonymous committed a440d22

SSHJobMan.poll() calls .start() if necesary; add maxwait option to .wait()

Also fixed %prog -> %%prog in usage string (interpolating __version__).

  • Participants
  • Parent commits c015b13

Comments (0)

Files changed (3)

 __author__  = '''Jim Dennis <answrguy@gmail.com>'''
 __url__     = '''http://bitbucket.org/jimd/classh/'''
 __license___= '''PSF (Python Software Foundation)'''
-__version__ = 0.07
+__version__ = 0.08
 
 
 import sys, os, string, signal, re
         self.started = False
         self.poolsize = 100
         self.jobtimeout = 300
+        self.sleeptime  = 0.2
 
         self.pool    = dict()         # for maintaining host/process data
         self.results = dict()  
         '''
         
         debug ('polling')
+        if not self.started:
+            self.start()
         reaped = list() 
         for key, job in self.pool.items():
             rv = job.proc.poll()
                 debug('Ignoring os.kill OSError')
 
 
-    def wait(self, snooze=0.2):
+    def wait(self, maxwait=None, snooze=None):
         '''
         '''
-        debug ('wait called called with %g sleep interval' % snooze)
+        debug ('wait called called with: %s %s ' % (maxwait,snooze))
+        return_after=None
+        if maxwait is not None:
+            return_after = time() + maxwait
+        if snooze is not None:
+            snooze = self.sleeptime
         if not self.started:
             self.start()
         while not self.done():
+            if return_after and time() > return_after:
+                return 
             sleep(snooze)
             self.poll()
 
     return results
 
 usage = '''
-usage %prog [switches] cmd [hostname|./file] [host]./file ...]
+usage %%prog [switches] cmd [hostname|./file] [host]./file ...]
 version %s
 ''' % __version__
  
 __author__  = '''Jim Dennis <answrguy@gmail.com>'''
 __url__     = '''http://bitbucket.org/jimd/classh/'''
 __license___= '''PSF (Python Software Foundation)'''
-__version__ = 0.07
+__version__ = 0.08
 
 
 import sys, os, string, signal, re
         self.started = False
         self.poolsize = 100
         self.jobtimeout = 300
+        self.sleeptime  = 0.2
 
         self.pool    = dict()         # for maintaining host/process data
         self.results = dict()  
         '''
         
         debug ('polling')
+        if not self.started:
+            self.start()
         reaped = list() 
         for key, job in self.pool.items():
             rv = job.proc.poll()
                 debug('Ignoring os.kill OSError')
 
 
-    def wait(self, snooze=0.2):
+    def wait(self, maxwait=None, snooze=None):
         '''
         '''
-        debug ('wait called called with %g sleep interval' % snooze)
+        debug ('wait called called with: %s %s ' % (maxwait,snooze))
+        return_after=None
+        if maxwait is not None:
+            return_after = time() + maxwait
+        if snooze is not None:
+            snooze = self.sleeptime
         if not self.started:
             self.start()
         while not self.done():
+            if return_after and time() > return_after:
+                return 
             sleep(snooze)
             self.poll()
 
     return results
 
 usage = '''
-usage %prog [switches] cmd [hostname|./file] [host]./file ...]
+usage %%prog [switches] cmd [hostname|./file] [host]./file ...]
 version %s
 ''' % __version__
  
 
 setup(
     name='classh',
-    version='0.07',
+    version='0.08',
     author='James T. Dennis',
     author_email='answrguy@gmail.com',
     license='PSF',