当前位置: 首页>>代码示例>>Python>>正文


Python Timer.communicate方法代码示例

本文整理汇总了Python中Timer.communicate方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.communicate方法的具体用法?Python Timer.communicate怎么用?Python Timer.communicate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Timer的用法示例。


在下文中一共展示了Timer.communicate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_hefesto_morb

# 需要导入模块: import Timer [as 别名]
# 或者: from Timer import communicate [as 别名]
def run_hefesto_morb():
    for thing in os.listdir(home_dir_list[0] + "/MORB_Control_Files"):
        print "\n" + "Opening HeFESTo for " + str(thing) + "\n"
        time.sleep(2)
        if "control" in os.listdir(home_dir_list[0]):
            os.remove(home_dir_list[0] + "/control")
        else:
            pass
        os.chdir(home_dir_list[0] + "/MORB_Control_Files")
        print "Copying" + str(thing) + " to path " + home_dir_list[0] + "..." + "\n"
        todir = home_dir_list[0] + "/" + "control"
        copyfromdir = home_dir_list[0] + "/MORB_Control_Files/" + str(thing)
        shutil.copy(copyfromdir, todir)
        os.chdir(home_dir_list[0])
        #src = str(thing)
        #drc = "control"
        #os.rename(src, drc)
        print("Performing calculations on {thing!r} ...".format(**vars()))
        print "\n"
        print "\n" + "Opening HeFESTo for calculations on " + str(thing) + " ..." + "\n"
        print "\n"
        #working_dir = os.curdir()
        #Popen(["main"], cwd=working_dir, stdin=PIPE)
        argz = home_dir_list[0] + "/main"
        p = subprocess.Popen(argz, stdin=None, stdout=None)
        t = Timer(800, p.kill)
        print "\n" + "Timeout timer started.  800 seconds until the process is terminated and the loop continues..." + "\n"
        t.start()
        t.communicate()
        t.cancel()
        print "\n" + "Copying output files to" +  home_dir_list[0]+ "/MORB_Output_Files' directory..." + "\n"
        try:
            os.remove("control")
        except:
            print "\n" + "Control file not found!" + "\n"
            pass
        if "fort.66" in os.listdir(home_dir_list[0]):
            print "\n" + "fort.66 found!" + "\n"
            theoutputfile66 = home_dir_list[0] + "/" + "fort.66"
            outputtodir66 = home_dir_list[0] + "/MORB_Output_Files/fort.66_files/" + "fort.66."+str(thing)+"_morb"
            shutil.move(theoutputfile66, outputtodir66)
        else:
            print "fort.66." + str(thing) + " not found!"
            pass
        if "fort.58" in os.listdir(home_dir_list[0]):
            print "\n" + "fort.58 found!" + "\n"
            theoutputfile58 = home_dir_list[0] + "/" + "fort.58"
            outputtodir58 = home_dir_list[0] + "/MORB_Output_Files/fort.58_files/" + "fort.58."+str(thing)+"_morb"
            shutil.move(theoutputfile58, outputtodir58)
        else:
            print "fort.58." + str(thing) + " not found!"
            pass
        if "fort.59" in os.listdir(home_dir_list[0]):
                print "\n" + "fort.59 found!" + "\n"
                theoutputfile59 = home_dir_list[0] + "/" + "fort.59"
                outputtodir59 = home_dir_list[0] + "/MORB_Output_Files/fort.59_files/" + "fort.59."+str(thing)+"_morb"
                shutil.move(theoutputfile59, outputtodir59)
        else:
            print "fort.59." + str(thing) + " not found!"
            pass
        print "LOOP FINISHED FOR " + str(thing)
        time.sleep(2)
        #except Exception:
           # traceback.print_exc()
           # print "\n"
           # print "Calculation failure for " + str(thing) + ".  Moving on..."
           # print "\n"
    else:
        print "\n"
        print "Done with MORB HeFESTo calculations.  Exiting script..." + "\n\n\n\n"
        print "___________________________________________________________"
        print "\n"
开发者ID:ScottHull,项目名称:Exoplanet-Pocketknife,代码行数:74,代码来源:EP_AutoHeFESTo.py


注:本文中的Timer.communicate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。