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()
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 coverage.stop() coverage.generate_report() # nohup python parallel_analyze.py -n 8 -d gpdb_upgrade_test >parallel_analyze.log 2>parallel_analyze.err & # python parallel_analyze.py -n 8 -d gpdb_upgrade_test
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 # No hope of pickling a precise Exception back to RemoteOperation. # So, provide meaningful trace as text and provide a non-zero return code # to signal to RemoteOperation that its Command invocation of gpoperation.py has failed. pretty_trace = str(e) + "\n" pretty_trace += 'Traceback (most recent call last):\n' pretty_trace += ''.join(traceback.format_list(tb_list)) logger.critical(pretty_trace) print >> sys.stderr, pretty_trace sys.exit(2) # signal that gpoperation.py has hit unexpected error else: pickled_ret = pickle.dumps(ret) # Pickle return data for stdout transmission finally: coverage.stop() coverage.generate_report() sys.stdout = old_stdout print pickled_ret sys.exit(0)