def tearDown(self): if os.path.exists("unknown.lp"): os.unlink("unknown.lp") TempfileManager.clear_tempfiles() if os.path.exists(os.path.join(currdir, 'result.yml')): os.remove(os.path.join(currdir, 'result.yml')) self.model = None
def run(args=None): # # Parse command-line options. # try: options_parser = \ construct_options_parser("scenariotreeserver [options] hostname") (options, arguments) = options_parser.parse_args(args=args) if arguments: assert len(arguments) == 1 options.host = arguments[0] else: options.host = None except SystemExit as _exc: # the parser throws a system exit if "-h" is specified - catch # it to exit gracefully. return _exc.code # for a one-pass execution, garbage collection doesn't make # much sense - so it is disabled by default. Because: It drops # the run-time by a factor of 3-4 on bigger instances. if options.disable_gc: gc.disable() else: gc.enable() if pstats_available and options.profile > 0: # # Call the main PH routine with profiling. # tfile = TempfileManager.create_tempfile(suffix=".profile") tmp = profile.runctx('run_server(options)',globals(),locals(),tfile) p = pstats.Stats(tfile).strip_dirs() p.sort_stats('time', 'cumulative') p = p.print_stats(options.profile) p.print_callers(options.profile) p.print_callees(options.profile) p = p.sort_stats('cumulative','calls') p.print_stats(options.profile) p.print_callers(options.profile) p.print_callees(options.profile) p = p.sort_stats('calls') p.print_stats(options.profile) p.print_callers(options.profile) p.print_callees(options.profile) TempfileManager.clear_tempfiles() ans = [tmp, None] else: # # Call the main routine without profiling. # ans = run_server(options) gc.enable() return ans
def run(args=None): # # Parse command-line options. # try: options_parser = \ construct_options_parser("scenariotreeserver [options] hostname") (options, arguments) = options_parser.parse_args(args=args) if arguments: assert len(arguments) == 1 options.host = arguments[0] else: options.host = None except SystemExit as _exc: # the parser throws a system exit if "-h" is specified - catch # it to exit gracefully. return _exc.code # for a one-pass execution, garbage collection doesn't make # much sense - so it is disabled by default. Because: It drops # the run-time by a factor of 3-4 on bigger instances. if options.disable_gc: gc.disable() else: gc.enable() if pstats_available and options.profile > 0: # # Call the main PH routine with profiling. # tfile = TempfileManager.create_tempfile(suffix=".profile") tmp = profile.runctx('run_server(options)', globals(), locals(), tfile) p = pstats.Stats(tfile).strip_dirs() p.sort_stats('time', 'cumulative') p = p.print_stats(options.profile) p.print_callers(options.profile) p.print_callees(options.profile) p = p.sort_stats('cumulative', 'calls') p.print_stats(options.profile) p.print_callers(options.profile) p.print_callees(options.profile) p = p.sort_stats('calls') p.print_stats(options.profile) p.print_callers(options.profile) p.print_callees(options.profile) TempfileManager.clear_tempfiles() ans = [tmp, None] else: # # Call the main routine without profiling. # ans = run_server(options) gc.enable() return ans
def main(args=None): # # Top-level command that executes the extensive form writer. # This is segregated from run_ef_writer to enable profiling. # # # Import plugins # import pyomo.environ # # Parse command-line options. # try: options_parser = construct_smps_options_parser("runph [options]") (options, args) = options_parser.parse_args(args=args) except SystemExit as _exc: # the parser throws a system exit if "-h" is specified - catch # it to exit gracefully. return _exc.code # # Control the garbage collector - more critical than I would like # at the moment. # if options.disable_gc: gc.disable() else: gc.enable() # # Run PH - precise invocation depends on whether we want profiling # output. # # if an exception is triggered and traceback is enabled, 'ans' # won't have a value and the return statement from this function # will flag an error, masking the stack trace that you really want # to see. ans = None if pstats_available and options.profile > 0: # # Call the main routine with profiling. # tfile = TempfileManager.create_tempfile(suffix=".profile") tmp = profile.runctx('exec_pysp2smps(options)', globals(), locals(), tfile) p = pstats.Stats(tfile).strip_dirs() p.sort_stats('time', 'cumulative') p = p.print_stats(options.profile) p.print_callers(options.profile) p.print_callees(options.profile) p = p.sort_stats('cumulative', 'calls') p.print_stats(options.profile) p.print_callers(options.profile) p.print_callees(options.profile) p = p.sort_stats('calls') p.print_stats(options.profile) p.print_callers(options.profile) p.print_callees(options.profile) TempfileManager.clear_tempfiles() ans = [tmp, None] else: # # Call the main routine without profiling. # if options.traceback: ans = exec_pysp2smps(options) else: try: try: ans = exec_pysp2smps(options) except ValueError: str = sys.exc_info()[1] print("VALUE ERROR:") print(str) raise except KeyError: str = sys.exc_info()[1] print("KEY ERROR:") print(str) raise except TypeError: str = sys.exc_info()[1] print("TYPE ERROR:") print(str) raise except NameError: str = sys.exc_info()[1] print("NAME ERROR:") print(str) raise except IOError: str = sys.exc_info()[1] print("IO ERROR:") print(str) raise except pyutilib.common.ApplicationError: str = sys.exc_info()[1] print("APPLICATION ERROR:") print(str) raise except RuntimeError: str = sys.exc_info()[1] print("RUN-TIME ERROR:") print(str) raise except: print("Encountered unhandled exception") traceback.print_exc() raise except: print("\n") print("To obtain further information regarding the " "source of the exception, use the --traceback option") gc.enable() return ans
def tearDown(self): global tmpdir TempfileManager.clear_tempfiles() TempfileManager.unique_files() os.chdir(tmpdir)
def launch_command(command, options, cmd_args=None, cmd_kwds=None, error_label="", disable_gc=False, profile_count=0, traceback=False): if cmd_args is None: cmd_args = () if cmd_kwds is None: cmd_kwds = {} # # Control the garbage collector - more critical than I would like # at the moment. # with PauseGC(disable_gc) as pgc: # # Run command - precise invocation depends on whether we want # profiling output, traceback, etc. # rc = 0 if pstats_available and (profile_count > 0): # # Call the main routine with profiling. # tfile = TempfileManager.create_tempfile(suffix=".profile") tmp = profile.runctx('command(options, *cmd_args, **cmd_kwds)', globals(), locals(), tfile) p = pstats.Stats(tfile).strip_dirs() p.sort_stats('time', 'cumulative') p = p.print_stats(profile_count) p.print_callers(profile_count) p.print_callees(profile_count) p = p.sort_stats('cumulative','calls') p.print_stats(profile_count) p.print_callers(profile_count) p.print_callees(profile_count) p = p.sort_stats('calls') p.print_stats(profile_count) p.print_callers(profile_count) p.print_callees(profile_count) TempfileManager.clear_tempfiles() rc = tmp else: # # Call the main PH routine without profiling. # if traceback: rc = command(options, *cmd_args, **cmd_kwds) else: try: try: rc = command(options, *cmd_args, **cmd_kwds) except ValueError: sys.stderr.write(error_label+"VALUE ERROR:\n") sys.stderr.write(str(sys.exc_info()[1])+"\n") raise except KeyError: sys.stderr.write(error_label+"KEY ERROR:\n") sys.stderr.write(str(sys.exc_info()[1])+"\n") raise except TypeError: sys.stderr.write(error_label+"TYPE ERROR:\n") sys.stderr.write(str(sys.exc_info()[1])+"\n") raise except NameError: sys.stderr.write(error_label+"NAME ERROR:\n") sys.stderr.write(str(sys.exc_info()[1])+"\n") raise except IOError: sys.stderr.write(error_label+"IO ERROR:\n") sys.stderr.write(str(sys.exc_info()[1])+"\n") raise except ConverterError: sys.stderr.write(error_label+"CONVERTER ERROR:\n") sys.stderr.write(str(sys.exc_info()[1])+"\n") raise except pyutilib.common.ApplicationError: sys.stderr.write(error_label+"APPLICATION ERROR:\n") sys.stderr.write(str(sys.exc_info()[1])+"\n") raise except RuntimeError: sys.stderr.write(error_label+"RUN-TIME ERROR:\n") sys.stderr.write(str(sys.exc_info()[1])+"\n") raise except: sys.stderr.write(error_label+ "Encountered unhandled exception:\n") if len(sys.exc_info()) > 1: sys.stderr.write(str(sys.exc_info()[1])+"\n") else: traceback.print_exc(file=sys.stderr) raise except: sys.stderr.write("\n") sys.stderr.write( "To obtain further information regarding the " "source of the exception, use the " "--traceback option\n") rc = 1 # # TODO: Once we incorporate options registration into # all of the PySP commands we will assume the # options object is always a PySPConfigBlock # if isinstance(options, PySPConfigBlock): ignored_options = dict((_c._name, _c.value(False)) for _c in options.unused_user_values()) if len(ignored_options): print("") print("*** WARNING: The following options were " "explicitly set but never accessed during " "execution of this command:") for name in ignored_options: print(" - %s: %s" % (name, ignored_options[name])) print("*** If you believe this is a bug, please report it " "to the PySP developers.") print("") return rc
def launch_command(command, options, cmd_args=None, cmd_kwds=None, error_label="", disable_gc=False, profile_count=0, log_level=logging.INFO, traceback=False): # This is not the effective level, but the # level on the current logger. We want to # return the logger to its original state # before this function exits prev_log_level = logger.level logger.setLevel(log_level) if cmd_args is None: cmd_args = () if cmd_kwds is None: cmd_kwds = {} # # Control the garbage collector - more critical than I would like # at the moment. # with PauseGC(disable_gc) as pgc: # # Run command - precise invocation depends on whether we want # profiling output, traceback, etc. # rc = 0 if pstats_available and (profile_count > 0): # # Call the main routine with profiling. # try: tfile = TempfileManager.create_tempfile(suffix=".profile") tmp = profile.runctx('command(options, *cmd_args, **cmd_kwds)', globals(), locals(), tfile) p = pstats.Stats(tfile).strip_dirs() p.sort_stats('time', 'cumulative') p = p.print_stats(profile_count) p.print_callers(profile_count) p.print_callees(profile_count) p = p.sort_stats('cumulative', 'calls') p.print_stats(profile_count) p.print_callers(profile_count) p.print_callees(profile_count) p = p.sort_stats('calls') p.print_stats(profile_count) p.print_callers(profile_count) p.print_callees(profile_count) TempfileManager.clear_tempfiles() rc = tmp finally: logger.setLevel(prev_log_level) else: # # Call the main PH routine without profiling. # if traceback: try: rc = command(options, *cmd_args, **cmd_kwds) finally: logger.setLevel(prev_log_level) else: try: try: rc = command(options, *cmd_args, **cmd_kwds) except ValueError: sys.stderr.write(error_label + "VALUE ERROR:\n") sys.stderr.write(str(sys.exc_info()[1]) + "\n") raise except KeyError: sys.stderr.write(error_label + "KEY ERROR:\n") sys.stderr.write(str(sys.exc_info()[1]) + "\n") raise except TypeError: sys.stderr.write(error_label + "TYPE ERROR:\n") sys.stderr.write(str(sys.exc_info()[1]) + "\n") raise except NameError: sys.stderr.write(error_label + "NAME ERROR:\n") sys.stderr.write(str(sys.exc_info()[1]) + "\n") raise except IOError: sys.stderr.write(error_label + "IO ERROR:\n") sys.stderr.write(str(sys.exc_info()[1]) + "\n") raise except ConverterError: sys.stderr.write(error_label + "CONVERTER ERROR:\n") sys.stderr.write(str(sys.exc_info()[1]) + "\n") raise except pyutilib.common.ApplicationError: sys.stderr.write(error_label + "APPLICATION ERROR:\n") sys.stderr.write(str(sys.exc_info()[1]) + "\n") raise except RuntimeError: sys.stderr.write(error_label + "RUN-TIME ERROR:\n") sys.stderr.write(str(sys.exc_info()[1]) + "\n") raise except: sys.stderr.write(error_label + "Encountered unhandled exception:\n") if len(sys.exc_info()) > 1: sys.stderr.write(str(sys.exc_info()[1]) + "\n") else: traceback.print_exc(file=sys.stderr) raise except: sys.stderr.write("\n") sys.stderr.write( "To obtain further information regarding the " "source of the exception, use the " "--traceback option\n") rc = 1 # # TODO: Once we incorporate options registration into # all of the PySP commands we will assume the # options object is always a PySPConfigBlock # if isinstance(options, PySPConfigBlock): options.check_usage(error=False) logger.setLevel(prev_log_level) return rc
def main(args=None): # # Top-level command that executes the extensive form writer. # This is segregated from run_ef_writer to enable profiling. # # # Import plugins # import pyomo.environ # # Parse command-line options. # try: options_parser = construct_smps_options_parser("runph [options]") (options, args) = options_parser.parse_args(args=args) except SystemExit as _exc: # the parser throws a system exit if "-h" is specified - catch # it to exit gracefully. return _exc.code # # Control the garbage collector - more critical than I would like # at the moment. # if options.disable_gc: gc.disable() else: gc.enable() # # Run PH - precise invocation depends on whether we want profiling # output. # # if an exception is triggered and traceback is enabled, 'ans' # won't have a value and the return statement from this function # will flag an error, masking the stack trace that you really want # to see. ans = None if pstats_available and options.profile > 0: # # Call the main routine with profiling. # tfile = TempfileManager.create_tempfile(suffix=".profile") tmp = profile.runctx('exec_pysp2smps(options)',globals(),locals(),tfile) p = pstats.Stats(tfile).strip_dirs() p.sort_stats('time', 'cumulative') p = p.print_stats(options.profile) p.print_callers(options.profile) p.print_callees(options.profile) p = p.sort_stats('cumulative','calls') p.print_stats(options.profile) p.print_callers(options.profile) p.print_callees(options.profile) p = p.sort_stats('calls') p.print_stats(options.profile) p.print_callers(options.profile) p.print_callees(options.profile) TempfileManager.clear_tempfiles() ans = [tmp, None] else: # # Call the main routine without profiling. # if options.traceback: ans = exec_pysp2smps(options) else: try: try: ans = exec_pysp2smps(options) except ValueError: str = sys.exc_info()[1] print("VALUE ERROR:") print(str) raise except KeyError: str = sys.exc_info()[1] print("KEY ERROR:") print(str) raise except TypeError: str = sys.exc_info()[1] print("TYPE ERROR:") print(str) raise except NameError: str = sys.exc_info()[1] print("NAME ERROR:") print(str) raise except IOError: str = sys.exc_info()[1] print("IO ERROR:") print(str) raise except pyutilib.common.ApplicationError: str = sys.exc_info()[1] print("APPLICATION ERROR:") print(str) raise except RuntimeError: str = sys.exc_info()[1] print("RUN-TIME ERROR:") print(str) raise except: print("Encountered unhandled exception") traceback.print_exc() raise except: print("\n") print("To obtain further information regarding the " "source of the exception, use the --traceback option") gc.enable() return ans
def tearDown(self): TempfileManager.clear_tempfiles()
def tearDownModule(): TempfileManager.clear_tempfiles() TempfileManager.tempdir = None TempfileManager.unique_files()
def tearDown(self): TempfileManager.clear_tempfiles() ReaderFactory.unregister('rtest3') ReaderFactory.unregister('stest3') ReaderFactory.unregister('wtest3')
def launch_command(command, options, cmd_args=None, cmd_kwds=None, error_label="", disable_gc=False, profile_count=0, log_level=logging.INFO, traceback=False): # This is not the effective level, but the # level on the current logger. We want to # return the logger to its original state # before this function exits prev_log_level = logger.level logger.setLevel(log_level) if cmd_args is None: cmd_args = () if cmd_kwds is None: cmd_kwds = {} # # Control the garbage collector - more critical than I would like # at the moment. # with PauseGC(disable_gc) as pgc: # # Run command - precise invocation depends on whether we want # profiling output, traceback, etc. # rc = 0 if pstats_available and (profile_count > 0): # # Call the main routine with profiling. # try: tfile = TempfileManager.create_tempfile(suffix=".profile") tmp = profile.runctx('command(options, *cmd_args, **cmd_kwds)', globals(), locals(), tfile) p = pstats.Stats(tfile).strip_dirs() p.sort_stats('time', 'cumulative') p = p.print_stats(profile_count) p.print_callers(profile_count) p.print_callees(profile_count) p = p.sort_stats('cumulative','calls') p.print_stats(profile_count) p.print_callers(profile_count) p.print_callees(profile_count) p = p.sort_stats('calls') p.print_stats(profile_count) p.print_callers(profile_count) p.print_callees(profile_count) TempfileManager.clear_tempfiles() rc = tmp finally: logger.setLevel(prev_log_level) else: # # Call the main PH routine without profiling. # if traceback: try: rc = command(options, *cmd_args, **cmd_kwds) finally: logger.setLevel(prev_log_level) else: try: try: rc = command(options, *cmd_args, **cmd_kwds) except ValueError: sys.stderr.write(error_label+"VALUE ERROR:\n") sys.stderr.write(str(sys.exc_info()[1])+"\n") raise except KeyError: sys.stderr.write(error_label+"KEY ERROR:\n") sys.stderr.write(str(sys.exc_info()[1])+"\n") raise except TypeError: sys.stderr.write(error_label+"TYPE ERROR:\n") sys.stderr.write(str(sys.exc_info()[1])+"\n") raise except NameError: sys.stderr.write(error_label+"NAME ERROR:\n") sys.stderr.write(str(sys.exc_info()[1])+"\n") raise except IOError: sys.stderr.write(error_label+"IO ERROR:\n") sys.stderr.write(str(sys.exc_info()[1])+"\n") raise except ConverterError: sys.stderr.write(error_label+"CONVERTER ERROR:\n") sys.stderr.write(str(sys.exc_info()[1])+"\n") raise except pyutilib.common.ApplicationError: sys.stderr.write(error_label+"APPLICATION ERROR:\n") sys.stderr.write(str(sys.exc_info()[1])+"\n") raise except RuntimeError: sys.stderr.write(error_label+"RUN-TIME ERROR:\n") sys.stderr.write(str(sys.exc_info()[1])+"\n") raise except: sys.stderr.write(error_label+ "Encountered unhandled exception:\n") if len(sys.exc_info()) > 1: sys.stderr.write(str(sys.exc_info()[1])+"\n") else: traceback.print_exc(file=sys.stderr) raise except: sys.stderr.write("\n") sys.stderr.write( "To obtain further information regarding the " "source of the exception, use the " "--traceback option\n") rc = 1 # # TODO: Once we incorporate options registration into # all of the PySP commands we will assume the # options object is always a PySPConfigBlock # if isinstance(options, PySPConfigBlock): options.check_usage(error=False) logger.setLevel(prev_log_level) return rc