def fork_new_process( self, module_name, resources, delete_temp_dir=True, optional_args=[], stdin=None, stdout=None, stderr=None, run_in_background=False, ): """Invoke the module whose fully-qualified opus name is module_name and pass it the pickled resources. Stores resources in pickle_file_path. If quiet=True, the console output for the command will not appear. """ self.module_name = module_name self._pickle_dir = mkdtemp() try: if resources is None: pickle_file_path = None else: pickle_file_path = os.path.join(self._pickle_dir, "resources.pickle") write_resources_to_file(pickle_file_path, resources) self.python_cmd = self._assemble_command_line_call(module_name, resources, pickle_file_path, optional_args) if stdin == PIPE: stdin = subprocess.PIPE if stdout == PIPE: stdout = subprocess.PIPE elif stdout == LOG: log_file_path = os.path.join(self._pickle_dir, "_log_.log") stdout = open(log_file_path, "w") if stderr == PIPE: stderr = subprocess.PIPE elif stderr == STDOUT: stderr = subprocess.STDOUT elif stderr == LOG: log_file_path = os.path.join(self._pickle_dir, "_errlog_.log") stderr = open(log_file_path, "w") logger.log_status("Invoking: %s" % " ".join(self.python_cmd)) self.popen = subprocess.Popen(self.python_cmd, stdin=stdin, stdout=stdout, stderr=stderr) if not run_in_background: self.wait() finally: if not run_in_background and delete_temp_dir: self.cleanup() returncode = self.popen.poll() if returncode != 0: if returncode != 10: logger.log_error("Error encountered in forked process with traceback:") return False else: return True
def fork_new_process(self, module_name, resources, delete_temp_dir=True, optional_args=[], stdin=None, stdout=None, stderr=None, run_in_background=False): """Invoke the module whose fully-qualified opus name is module_name and pass it the pickled resources. Stores resources in pickle_file_path. If quiet=True, the console output for the command will not appear. """ self.module_name = module_name self._pickle_dir = mkdtemp() try: if resources is None: pickle_file_path = None else: pickle_file_path = os.path.join(self._pickle_dir, 'resources.pickle') write_resources_to_file(pickle_file_path, resources) self.python_cmd = \ self._assemble_command_line_call(module_name, resources, pickle_file_path, optional_args) if stdin == PIPE: stdin = subprocess.PIPE if stdout == PIPE: stdout = subprocess.PIPE elif stdout == LOG: log_file_path = os.path.join(self._pickle_dir, '_log_.log') stdout = open(log_file_path, "w") if stderr == PIPE: stderr = subprocess.PIPE elif stderr == STDOUT: stderr = subprocess.STDOUT elif stderr == LOG: log_file_path = os.path.join(self._pickle_dir, '_errlog_.log') stderr = open(log_file_path, "w") logger.log_status("Invoking: %s" % " ".join(self.python_cmd)) self.popen = subprocess.Popen(self.python_cmd, stdin=stdin, stdout=stdout, stderr=stdout) if not run_in_background: self.wait() finally: if not run_in_background and delete_temp_dir: pass
class OptionGroup(GenericOptionGroup): def __init__(self): GenericOptionGroup.__init__(self, usage="python %prog [options] run_id [pickle_file]", description="dump resources.pickle from services db for the given run_id") self.parser.add_option("-p", "--project-name", dest="project_name", default='',help="The project name") if __name__ == "__main__": option_group = OptionGroup() parser = option_group.parser (options, args) = parser.parse_args() try: run_id = int(args[0]) except IndexError: parser.error("run_id must be provided.") parser.print_help() sys.exit(1) if len(args) == 2: pickle_file = args[1] else: pickle_file = "resources.pickle" run_manager = RunManager(option_group.get_services_database_configuration(options)) if options.project_name: run_manager.update_environment_variables(run_resources={'project_name':options.project_name}) resources = run_manager.get_resources_for_run_id_from_history(run_id=run_id) write_resources_to_file(pickle_file, resources)
def copy_resources_to_remote_host(self, config): pickle_dir = mkdtemp() pickle_file_path = os.path.join(pickle_dir, 'resources.pickle') write_resources_to_file(pickle_file_path, config) # copy configuration as resources.pickle to the remote machine self.copy_file_to_remote_host(pickle_file_path)
dest="project_name", default='', help="The project name") if __name__ == "__main__": option_group = OptionGroup() parser = option_group.parser (options, args) = parser.parse_args() try: run_id = int(args[0]) except IndexError: parser.error("run_id must be provided.") parser.print_help() sys.exit(1) if len(args) == 2: pickle_file = args[1] else: pickle_file = "resources.pickle" run_manager = RunManager( option_group.get_services_database_configuration(options)) if options.project_name: run_manager.update_environment_variables( run_resources={'project_name': options.project_name}) resources = run_manager.get_resources_for_run_id_from_history( run_id=run_id) write_resources_to_file(pickle_file, resources)