def simple_main(createOptionParserFn, createCommandFn, mainOptions=None): """ createOptionParserFn : a function that takes no arguments and returns an OptParser createCommandFn : a function that takes two argument (the options and the args (those that are not processed into options) and returns an object that has "run" and "cleanup" functions. Its "run" function must run and return an exit code. "cleanup" will be called to clean up before the program exits; this can be used to clean up, for example, to clean up a worker pool mainOptions can include: forceQuietOutput (map to bool), programNameOverride (map to string) suppressStartupLogMessage (map to bool) useHelperToolLogging (map to bool) setNonuserOnToolLogger (map to bool, defaults to false) pidfilename (string) parentpidvar (string) """ coverage = GpCoverage() coverage.start() try: simple_main_internal(createOptionParserFn, createCommandFn, mainOptions) finally: coverage.stop() coverage.generate_report()
options.stat_mem) logger.info('=== Analysis complete ===') def store_results_to_fs(q, location, dbname, filenam): result_file = open(dbname + "_" + filenam + ".csv", 'w+') while not q.empty(): result_file.write(q.get() + "\n") result_file.close() #------------------------------- Mainline -------------------------------- #Initialization coverage = GpCoverage() coverage.start() logger = get_default_logger() res_queue = Queue() err_queue = Queue() #Parse input parameters and check for validity options = parseargs() #Print the partition list orchestrator(options) store_results_to_fs(res_queue, options.location, options.dbname, options.filename) #while not res_queue.empty(): #print res_queue.get() #Stopping
# log initialization must be done only AFTER rerouting stdout from gppylib import gplog from gppylib.mainUtils import getProgramName from gppylib.commands import unix hostname = unix.getLocalHostname() username = unix.getUserName() execname = pickle.load(sys.stdin) gplog.setup_tool_logging(execname, hostname, username) logger = gplog.get_default_logger() operation = pickle.load(sys.stdin) from gppylib.gpcoverage import GpCoverage coverage = GpCoverage() coverage.start() try: ret = operation.run() except Exception, e: exc_type, exc_value, exc_traceback = sys.exc_info() tb_list = traceback.extract_tb(exc_traceback) try: # TODO: Build an ExceptionCapsule that can return the traceback # to RemoteOperation as well. See Pyro. # logger.exception(e) # logging 'e' could be necessary for traceback pickled_ret = pickle.dumps(e) # Pickle exception for stdout transmission except Exception, f: # logger.exception(f) # 'f' is not important to us, except for debugging perhaps