Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tune/rllib] Ignore directory exists errors to tackle race conditions #28401

Merged
merged 1 commit into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/ray/tune/impl/tuner_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def _setup_create_experiment_checkpoint_dir(
run_config.name,
)
if not os.path.exists(path):
os.makedirs(path)
os.makedirs(path, exist_ok=True)
return path

# This has to be done through a function signature (@property won't do).
Expand Down
4 changes: 3 additions & 1 deletion rllib/algorithms/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ class directly. Note that this arg can also be specified via
timestr = datetime.today().strftime("%Y-%m-%d_%H-%M-%S")
logdir_prefix = "{}_{}_{}".format(str(self), env_descr, timestr)
if not os.path.exists(DEFAULT_RESULTS_DIR):
os.makedirs(DEFAULT_RESULTS_DIR)
# Possible race condition if dir is created several times on
# rollout workers
os.makedirs(DEFAULT_RESULTS_DIR, exist_ok=True)
logdir = tempfile.mkdtemp(prefix=logdir_prefix, dir=DEFAULT_RESULTS_DIR)

# Allow users to more precisely configure the created logger
Expand Down
5 changes: 1 addition & 4 deletions rllib/offline/json_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ def __init__(
else:
path = os.path.abspath(os.path.expanduser(path))
# Try to create local dirs if they don't exist
try:
os.makedirs(path)
except OSError:
pass # already exists
os.makedirs(path, exist_ok=True)
assert os.path.exists(path), "Failed to create {}".format(path)
self.path_is_uri = False
self.path = path
Expand Down
8 changes: 1 addition & 7 deletions rllib/policy/tf_policy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import errno
import logging
import math
import os
Expand Down Expand Up @@ -529,12 +528,7 @@ def export_checkpoint(
self, export_dir: str, filename_prefix: str = "model"
) -> None:
"""Export tensorflow checkpoint to export_dir."""
try:
os.makedirs(export_dir)
except OSError as e:
# ignore error if export dir already exists
if e.errno != errno.EEXIST:
raise
os.makedirs(export_dir, exist_ok=True)
save_path = os.path.join(export_dir, filename_prefix)
with self.get_session().graph.as_default():
saver = tf1.train.Saver()
Expand Down
2 changes: 1 addition & 1 deletion rllib/policy/torch_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ def export_model(self, export_dir: str, onnx: Optional[int] = None) -> None:
}

if not os.path.exists(export_dir):
os.makedirs(export_dir)
os.makedirs(export_dir, exist_ok=True)

seq_lens = self._dummy_batch[SampleBatch.SEQ_LENS]
if onnx:
Expand Down
2 changes: 1 addition & 1 deletion rllib/policy/torch_policy_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ def export_model(self, export_dir: str, onnx: Optional[int] = None) -> None:
}

if not os.path.exists(export_dir):
os.makedirs(export_dir)
os.makedirs(export_dir, exist_ok=True)

seq_lens = self._dummy_batch[SampleBatch.SEQ_LENS]
if onnx:
Expand Down