如何确保文件在读取之前已写入磁盘

问题描述 投票:0回答:0

我想读取由

fast-downward
规划器生成的 plan.txt 文件,为此我使用
subprocess
如下:

import subprocess

search_options = "lama-first"
## Call Planner
cmd = [
    "python3",
    self.planner_path,
    "--alias",
    search_options,
    "--plan-file",
    self.plan_path,
    self.domain_path,
    self.problem_path,
]
## Read plan.txt
cmd2 = ["cat", self.plan_path]
subprocess.run(cmd, shell=False, stdout=subprocess.PIPE)

plan = []
try:
    # Huge dealy to be sure that the plan is written to the txt file
    time.sleep(1)
    result2 = subprocess.run(cmd2, shell=False, stdout=subprocess.PIPE)
    plan = result2.stdout.decode("utf-8")
except:
    pass

你能告诉我什么是确保计划在尝试读取之前已写入磁盘的最佳方法,而不是增加巨大的时间延迟吗?提前致谢。

python subprocess read-write
© www.soinside.com 2019 - 2024. All rights reserved.