gpt4 book ai didi

abaqus - 超时后,Abaqus API 中的 waitForCompletion(timeout) 实际上并没有终止作业

转载 作者:行者123 更新时间:2023-12-04 08:16:48 28 4
gpt4 key购买 nike

我正在对一些 Abaqus 模拟进行参数化扫描,因此我正在使用 waitForCompletion()防止脚本过早运行的功能。然而,有时参数组合会导致模拟在扫描中的一个或两个参数上挂起大约半小时到一个小时,而大多数参数组合只需要大约 10 分钟。我不需要所有的数据点,所以我宁愿牺牲一两个结果来支持更多的模拟。因此我尝试使用 waitForCompletion(timeout)如文档所示 here .但它不起作用 - 它最终就像一个不确定的 waitForCompletion ,无论我将等待时间设置得有多低。我正在使用 Abaqus 2017,我想知道是否还有其他人使用过此功能,如果有,如何使用?
虽然我可以使用一种解决方法,例如添加自定义超时函数并使用 kill()在工作中发挥作用,我更喜欢使用 Abaqus API 的内置功能,因此非常感谢任何帮助!

最佳答案

好像是从某个版本开始timeOut从此方法中删除了可选参数:比较 v6.7 文档中的“脚本引用手册”条目和 v6.14 .
您有几个选择:

  • 来自 Abaqus API:检查 my_abaqus_script.023模拟期间文件仍然存在:

  • import os, time

    timeOut = 600
    total_time = 60
    time.sleep(60)

    # whait untill the the job is completed
    while os.path.isfile('my_job_name.023') == True:
    if total_time > timeOut:
    my_job.kill()
    total_time += 60
    time.sleep(60)
  • 从外面:使用 subprocess 启 Action 业

  • Note: don't use interactive keyword in your command because it blocks the execution of the script while the simulation process is active.


    import subprocess, os, time

    my_cmd = 'abaqus job=my_abaqus_script analysis cpus=1'
    proc = subprocess.Popen(
    my_cmd,
    cwd=my_working_dir,
    stdout='my_study.log',
    stderr='my_study.err',
    shell=True
    )
  • 并检查起诉 poll() 的子进程的返回码(另见 returncode ):

  • timeOut = 600
    total_time = 60
    time.sleep(60)

    # whait untill the the job is completed
    while proc.poll() is None:
    if total_time > timeOut:
    proc.terminate()
    total_time += 60
    time.sleep(60)

  • 或等待使用 wait() 达到超时时间

  • timeOut = 600

    try:
    proc.wait(timeOut)
    except subprocess.TimeoutExpired:
    print('TimeOut reached!')

    Note: I know that terminate() and wait() methods should work in theory but I haven't tried this solution myself. So maybe there will be some additional complications (like looking for all children processes created by Abaqus using psutil.Process(proc.pid) )

    关于abaqus - 超时后,Abaqus API 中的 waitForCompletion(timeout) 实际上并没有终止作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65670445/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com