Changeset 3271

Show
Ignore:
Timestamp:
01/26/12 21:06:56 (4 months ago)
Author:
erkn
Message:

Refactor: piping is now optional

Location:
branches/mcxtrace-1.0/src/mcrun2
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/mcxtrace-1.0/src/mcrun2/main.py

    r3269 r3271  
    168168        options.use_mpi = True 
    169169        options.cc = 'mpicc' 
     170        options.mpirun = 'mpirun' 
    170171    else: 
    171172        options.use_mpi = False 
  • branches/mcxtrace-1.0/src/mcrun2/mcstas.py

    r3270 r3271  
    3737        self.executable = executable 
    3838 
    39     def run(self, args=None): 
     39    def run(self, args=None, pipe=False): 
    4040        ''' Run external process with args ''' 
    4141 
     42        # Unsafe to use [] as default (reference) 
    4243        if args is None: 
    4344            args = [] 
     45 
     46        # Redirect stdout and stderr? 
     47        pipe = pipe and PIPE or None 
    4448 
    4549        # Run executable 
    4650        LOG.debug('CMD: %s %s' % (self.executable, args)) 
    4751        fid = Popen([self.executable] + args, 
    48                     stdout=None, 
    49                     stderr=None) 
     52                    stdout=pipe, 
     53                    stderr=pipe) 
    5054        stdout, stderr = fid.communicate() 
    5155 
     
    109113 
    110114 
    111     def run(self): 
     115    def run(self, pipe=False): 
    112116        ''' Run simulation ''' 
    113117        args = [] 
    114118        options = self.options 
    115         print repr(options) 
    116  
    117119        mpi = self.options.use_mpi 
    118120 
     
    138140        if not mpi: 
    139141            LOG.info('Running: %s' % self.binpath) 
    140             Process(self.binpath).run(args) 
     142            Process(self.binpath).run(args, pipe=pipe) 
    141143        else: 
    142144            LOG.info('Running via MPI: %s' % self.binpath) 
    143145            mpi_args = ['-np', str(options.mpi), self.binpath] 
    144146            mpi_args += args 
    145             Process('mpirun').run(mpi_args) 
     147            Process(options.mpirun).run(mpi_args, pipe=pipe) 
    146148 
    147149