Unverified Commit 2644707c authored by Taylor Robie's avatar Taylor Robie Committed by GitHub
Browse files

prevent async process from writing alive file until the main process has...

prevent async process from writing alive file until the main process has created the cache root (#5614)
parent 31d38900
...@@ -479,18 +479,21 @@ def _generation_loop(num_workers, # type: int ...@@ -479,18 +479,21 @@ def _generation_loop(num_workers, # type: int
gc.collect() gc.collect()
def _parse_flagfile(flagfile): def wait_for_path(fpath):
"""Fill flags with flagfile written by the main process."""
tf.logging.info("Waiting for flagfile to appear at {}..."
.format(flagfile))
start_time = time.time() start_time = time.time()
while not tf.gfile.Exists(flagfile): while not tf.gfile.Exists(fpath):
if time.time() - start_time > rconst.TIMEOUT_SECONDS: if time.time() - start_time > rconst.TIMEOUT_SECONDS:
log_msg("Waited more than {} seconds. Concluding that this " log_msg("Waited more than {} seconds. Concluding that this "
"process is orphaned and exiting gracefully." "process is orphaned and exiting gracefully."
.format(rconst.TIMEOUT_SECONDS)) .format(rconst.TIMEOUT_SECONDS))
sys.exit() sys.exit()
time.sleep(1) time.sleep(1)
def _parse_flagfile(flagfile):
"""Fill flags with flagfile written by the main process."""
tf.logging.info("Waiting for flagfile to appear at {}..."
.format(flagfile))
wait_for_path(flagfile)
tf.logging.info("flagfile found.") tf.logging.info("flagfile found.")
# `flags` module opens `flagfile` with `open`, which does not work on # `flags` module opens `flagfile` with `open`, which does not work on
...@@ -504,6 +507,8 @@ def _parse_flagfile(flagfile): ...@@ -504,6 +507,8 @@ def _parse_flagfile(flagfile):
def write_alive_file(cache_paths): def write_alive_file(cache_paths):
"""Write file to signal that generation process started correctly.""" """Write file to signal that generation process started correctly."""
wait_for_path(cache_paths.cache_root)
log_msg("Signaling that I am alive.") log_msg("Signaling that I am alive.")
with tf.gfile.Open(cache_paths.subproc_alive, "w") as f: with tf.gfile.Open(cache_paths.subproc_alive, "w") as f:
f.write("Generation subproc has started.") f.write("Generation subproc has started.")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment