【问题标题】:How to get return code from GAMS Python API run如何从 GAMS Python API 运行中获取返回码
【发布时间】:2018-01-04 20:32:56
【问题描述】:

有没有办法通过在 GAMS Python API 中运行 GamsJob 来获取返回码?意思是,在我执行 job.run() 之后,这个执行的返回代码是否存储在我可以访问的地方?

【问题讨论】:

    标签: python gams-math


    【解决方案1】:

    如果返回码非零,job.run() 将抛出异常,返回码存储在属性.rc 中。因此:

    try:
        job.run()
    except GamsExceptionExecution as e:
        print(e.rc)  # This is a non-zero return code
    

    【讨论】:

      【解决方案2】:

      返回码应该和运行文件在同一个文件夹中。

      例如,使用此处详细介绍的 transport1.py 示例https://gams.com/latest/docs/apis/examples_python/index.html,您可以找到 .lst 文件,如下所示:

      • t1._file_name 为您提供“PATH\transport.gms”(其中 transport.gms 是定义要运行的模型的文件)
      • t1._job_name 为您提供作业名称
      • 从那里:PATH\t1._job_name.lst 是lst 文件,如下:

        os.path.dirname(t1._file_name)+"\\"+t1._job_name+".lst"
        

      【讨论】:

        猜你喜欢
        • 2011-05-06
        • 2013-01-25
        • 1970-01-01
        • 1970-01-01
        • 2015-09-30
        • 2021-03-31
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多