def _submit_task_with_template(self, task_ids):
        '''Submit tasks by interpolating a shell script defined in job_template'''
        runtime = self.config
        runtime.update({
            'workdir': os.getcwd(),
            'cur_dir': os.getcwd(),  # for backward compatibility
            'verbosity': env.verbosity,
            'sig_mode': env.config.get('sig_mode', 'default'),
            'run_mode': env.config.get('run_mode', 'run'),
            'home_dir': os.path.expanduser('~')
        })
        if '_runtime' in env.sos_dict:
            runtime.update({
                x: env.sos_dict['_runtime'][x]
                for x in ('nodes', 'cores', 'workdir', 'mem', 'walltime')
                if x in env.sos_dict['_runtime']
            })
        if 'nodes' not in runtime:
            runtime['nodes'] = 1
        if 'cores' not in runtime:
            runtime['cores'] = 1

        # let us first prepare a task file
        job_text = ''
        for task_id in task_ids:
            runtime['task'] = task_id
            try:
                job_text += cfg_interpolate(self.job_template, runtime)
                job_text += '\n'
            except Exception as e:
                raise ValueError(
                    f'Failed to generate job file for task {task_id}: {e}')

        filename = task_ids[0] + ('.sh' if len(task_ids) == 1 else
                                  f'-{task_ids[-1]}.sh')
        # now we need to write a job file
        job_file = os.path.join(
            os.path.expanduser('~'), '.sos', 'tasks', filename)
        # do not translate newline under windows because the script will be executed
        # under linux/mac
        with open(job_file, 'w', newline='') as job:
            job.write(job_text)

        # then copy the job file to remote host if necessary
        self.agent.send_task_file(job_file)

        try:
            cmd = f'bash ~/.sos/tasks/{filename}'
            self.agent.run_command(cmd, wait_for_task=self.wait_for_task)
        except Exception as e:
            raise RuntimeError(f'Failed to submit task {task_ids}: {e}')
        return True
def _submit_task_with_template ( self , task_ids ) : runtime = self . config runtime . update ( { 'workdir' : os . getcwd ( ) , 'cur_dir' : os . getcwd ( ) , 'verbosity' : env . verbosity , 'sig_mode' : env . config . get ( 'sig_mode' , 'default' ) , 'run_mode' : env . config . get ( 'run_mode' , 'run' ) , 'home_dir' : os . path . expanduser ( '~' ) } ) if '_runtime' in env . sos_dict : runtime . update ( { x : env . sos_dict [ '_runtime' ] [ x ] for x in ( 'nodes' , 'cores' , 'workdir' , 'mem' , 'walltime' ) if x in env . sos_dict [ '_runtime' ] } ) if 'nodes' not in runtime : runtime [ 'nodes' ] = 1 if 'cores' not in runtime : runtime [ 'cores' ] = 1 job_text = '' for task_id in task_ids : runtime [ 'task' ] = task_id try : job_text += cfg_interpolate ( self . job_template , runtime ) job_text += '\n' except Exception as e : raise ValueError ( f'Failed to generate job file for task {task_id}: {e}' ) filename = task_ids [ 0 ] + ( '.sh' if len ( task_ids ) == 1 else f'-{task_ids[-1]}.sh' ) job_file = os . path . join ( os . path . expanduser ( '~' ) , '.sos' , 'tasks' , filename ) with open ( job_file , 'w' , newline = '' ) as job : job . write ( job_text ) self . agent . send_task_file ( job_file ) try : cmd = f'bash ~/.sos/tasks/{filename}' self . agent . run_command ( cmd , wait_for_task = self . wait_for_task ) except Exception as e : raise RuntimeError ( f'Failed to submit task {task_ids}: {e}' ) return True
Submit tasks by interpolating a shell script defined in job_template