在 `make_video()` 中,可能无法在 Windows 上删除临时 GIF 文件
import os
import tempfile
with tempfile.NamedTemporaryFile(delete=False) as f:
filename = f.name
f.write(b"test")
try:
os.remove(filename)
print("remove succeeded")
except OSError as e:
print(f"remove failed: {e}")
print(f"file exists after with: {os.path.exists(filename)}")
This produces:
"remove failed: [WinError 32] ..."
In contrast, moving the os.remove() call outside the NamedTemporaryFile context succeeds:
import os
import tempfile
with tempfile.NamedTemporaryFile(delete=False) as f:
filename = f.name
f.write(b"test")
try:
os.remove(filename)
print("remove succeeded")
except OSError as e:
print(f"remove failed: {e}")
print(f"file exists: {os.path.exists(filename)}")
This results in the temporary file being successfully removed.
内容来源: lanpa/tensorboardX