Changeset 240 for tbroadcast


Ignore:
Timestamp:
Aug 28, 2006, 1:20:02 PM (18 years ago)
Author:
garonne
Message:

improve tbroadcast script

Location:
tbroadcast/v2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tbroadcast/v2/python/tbroadcast.py

    r239 r240  
    4949    def instanciate_packages(self):
    5050        # We create the schedule of the work units
    51         print '# First, we initialize the DAG by parsing cmt show uses (takes a certain time... huk should be improved asap) '
     51        print '# First, we initialize the DAG by parsing cmt show uses'
    5252        cmd = 'cmt show uses'
    5353        status, output = commands.getstatusoutput (cmd)
     
    117117                        sys.exit(-1)
    118118                    self.packages[result[0]]['path'] = full_path
    119         print '# really takes a certain time ... '
     119        print '# Sometimes takes a certain time (should be improved asap)'
    120120
    121121    def get_current_package(self):   
     
    198198        packages = self.get_next_work_units()
    199199        if len(packages) !=0:
    200             print '\n# Execute parallel actions within ', packages                     
     200            print '\n#--------------------------------------------------------------'   
     201            print '# Execute parallel actions within packages', packages                     
    201202            for package in packages:
    202203                self.add_work_unit (package, command)
     
    218219    # the work the threads will have to do
    219220    def do_execute(self, arg):
    220         path = self.get_work_area_path (arg['package'])   
    221         self.set_work_unit_status (arg['package'], 'running')     
    222         cmd = "cmt -use="+ arg['package'] + " run '"+ arg['cmd'] + "'"
    223         os.chdir(path)       
    224         print '#--------------------------------------------------------------'
    225         print '# Now trying ['+ arg['cmd']+'] in ' + path
    226         print '#--------------------------------------------------------------'
    227         cmd = arg['cmd']
    228         status, output, error, pythonError  = exeCommand(cmd,  iTimeout = 10)     
    229         self.suppress_work_unit (arg['package'])
    230         self.set_work_unit_status (arg['package'], 'done')
    231         # status, output= commands.getstatusoutput(cmd)
    232         #print output
    233         #if status != 0:
    234         #   raise RuntimeError(output)
    235         return {'output':output, 'cmd': arg['cmd'], 'package':arg['package']}
     221      path = self.get_work_area_path (arg['package'])
     222      if path == None:
     223          raise RuntimeError('Path to package '+ arg['package'] +' not found')
     224      self.set_work_unit_status (arg['package'], 'running')     
     225      cmd = "cmt -use="+ arg['package'] + " run '"+ arg['cmd'] + "'"
     226      os.chdir(path)       
     227      print '#--------------------------------------------------------------'
     228      print '# Now trying ['+ arg['cmd']+'] in ' + path
     229      print '#--------------------------------------------------------------'
     230      cmd = arg['cmd']
     231      status, output, error, pythonError  = exeCommand(cmd,  iTimeout = 10)     
     232      self.suppress_work_unit (arg['package'])
     233      self.set_work_unit_status (arg['package'], 'done')
     234      # status, output= commands.getstatusoutput(cmd)
     235      #if status != 0:
     236      #   raise RuntimeError(output)
     237      return {'output':output, 'cmd': arg['cmd'], 'package':arg['package']}
    236238             
    237239    # this will be called when an exception occurs within a thread
    238240    def handle_exception(self, request, exc_info):
    239241        #traceback.print_stack()
    240         print "# Exception occured in request #%s: %s" % \
    241           (request.requestID, exc_info[1])
     242      print '#--------------------------------------------------------------'       
     243      #print "# Exception occured in request #%s: %s" %(request.requestID, exc_info[1])
     244      print "# Exception occured: %s" %(exc_info[1])
     245      print '#--------------------------------------------------------------'   
     246      sys.exit(-1)
    242247#--------- EoF --------#   
  • tbroadcast/v2/scripts/tbroadcast

    r237 r240  
    1 #!/usr/bin/env python2
     1#!/usr/bin/env python
    22#----------------------------------#
    33# -- Author: V.Garonne
     
    1313from tbroadcast import Scheduler
    1414
     15def usage():
     16    print 'Usage : > tbroadcast [global options] [<command>]'
     17    print '# command :'
     18    print '#   <command>: command to execute'
     19    print '# global options :'
     20    print '#   -nb=<num_worker>]                  : Total number of threads'
     21    print '#   -help]                             : Print help'
     22
    1523if __name__ == '__main__':
    16 
    17     if len(sys.argv) ==1 :
    18         print 'Usage : > tbroadcast [-nb=<num_worker>] <command>'
    19         sys.exit(-1)   
    20     num_worker = 20   
    21     for arg in sys.argv:           
     24    # Default options
     25    num_worker = 20
     26    command    = ''   
     27    for arg in sys.argv[1:len(sys.argv)]:           
    2228         if arg[0]=='-':
    23              if string.split(arg,'=')[0] == '-nb':
     29             option = string.split(arg,'=')[0]
     30             if option == '-nb':
    2431                num_worker = int (string.split(arg,'=')[1])         
     32             else:
     33                usage()
     34                sys.exit(-1)   
     35               
    2536         else:
    2637              command = arg
    27                      
    28     # we create a pool of num_worker worker threads
    29     #print 'num_worker', num_worker , command
     38
    3039    master = Scheduler (num_workers=num_worker)       
    3140    master.execute_all (command)
Note: See TracChangeset for help on using the changeset viewer.