-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Description
Hi, this code fragment somehow can have unexpected behaviour on (some?) linux machines. For me subprocess.check_call
fails, because on the OS side, the file handle to the temporary file has not been closed yet (despite the explicit .close() statement) - debugging the check_call leads to a Text file busy
error message).
sagemaker-python-sdk/src/sagemaker/git_utils.py
Lines 281 to 287 in ac353b2
with tempfile.NamedTemporaryFile() as sshnoprompt: | |
write_pipe = open(sshnoprompt.name, "w") | |
write_pipe.write("ssh -oBatchMode=yes $@") | |
write_pipe.close() | |
os.chmod(sshnoprompt.name, 0o511) | |
my_env["GIT_SSH"] = sshnoprompt.name | |
subprocess.check_call(["git", "clone", repo_url, dest_dir], env=my_env) |
Interestingly, the code works fine on my mac, so the behaviour seems somewhat OS dependent.
Instead, changing the NamedTemporaryFile
to a TemporaryDirectory
and creating the helper script within the context manager of the TemporaryDirectory
should work, I think.