def _submit_jobs(self, func, iterable, mode, chunksize=1, dependencies=[]):
        if mode not in ['map', 'reduce']:
            raise ValueError('mode must be one of "map" or "reduce"')
        moreData = True
        allJobs = []
        iterable = iter(iterable)
        # for each partition
        while moreData:
            curChunks = itertools.islice(iterable, chunksize)
            # save the function and data to a new pickle file
            workFile = tempfile.NamedTemporaryFile(prefix='SGE_%s_'%mode, dir=os.path.abspath('.'), delete=False, mode='wb')
            #print os.environ['PYTHONPATH']
            #print pickle.dumps(os.environ['PYTHONPATH'])
            #pickle.dump(os.environ['PYTHONPATH'], workFile)   # dump all data about environment variables
            pickle.dump(self.initializer, workFile, -1)
            if mode == 'map':
                pickle.dump(self.initargs, workFile, -1)
            try:
                pickle.dump(func, workFile, -1)         # dump mapping function
            except __HOLE__ as e:
                # Failure pickling function-- probably a lambda function
                os.remove(workFile.name)
                raise e  # Can't pickle lambda or shell-defined functions
            curDataCount = 0
            for data in curChunks:
                curDataCount += 1
                pickle.dump(data, workFile, -1)
            if curDataCount == 0:
                # no data was sliced from original dataset-- we are done
                moreData = False
                os.remove(workFile.name)
            else:
                # submit an SGE job on this dataset slice
                outfile = tempfile.NamedTemporaryFile(prefix='SGE_%s_results_'%mode, dir=os.path.abspath('.'), delete=False)
                cmd = 'cd %s; $python_cmd "%s" --mode=%s "%s" "%s"' % (os.path.split(workFile.name)[0], os.path.abspath(__file__), mode, workFile.name, outfile.name)
                curJob = Job(os.path.split(workFile.name)[1], cmd)
                for job in dependencies:
                    curJob.addDependency(job)
                curJob.inputFile = workFile.name
                curJob.outputFile = outfile.name
                build_submission(os.path.abspath('.'), [curJob], use_grid_engine=self.use_grid_engine)
                allJobs.append(curJob)
        return allJobs
dataset/ETHPy150Open uci-cbcl/tree-hmm/treehmm/sge.py/SGEPool._submit_jobs