Processing a list of shells parallel.

def process_shells_parallel(self, shells):
        """Processing a list of shells parallel."""
        output = []
        success = True
        with closing(multiprocessing.Pool(multiprocessing.cpu_count())) as pool:
            for result in [Adapter(entry) for entry in pool.map(worker, [shell for shell in shells])]:
                output += result.output
                the_shell = [shell for shell in shells if shell['id'] == result.id][0]
                self.__handle_variable(the_shell['entry'], result.output)
                if not result.success:
                    success = False
        if success:
            self.logger.info("Parallel Processing Bash code: finished")
            return {'success': True, 'output': output}

        for line in self.run_cleanup(shells[0]['env'], 99):
            output.append(line)
        self.logger.error("Pipeline has failed: immediately leaving!")
        self.event.failed()
        return {'success': False, 'output': output}