Interview Prep/Python for DevOps/Runtime, file, subprocess & encoding errors

`OSError: [Errno 18] Invalid cross-device link` when calling `os.rename`.

AdvancedTroubleshootingRuntime, file, subprocess & encoding errors
Answer

Likely causes → os.rename/os.replace cannot move across filesystems (for example /tmp tmpfs to /data on disk, or between Docker volumes).

Diagnose →

df /tmp /data      # different devices

Fix → Use shutil.move() (copies then deletes), or create the temp file in the destination directory so the final os.replace stays atomic on one filesystem.

Prevent → For atomic writes, always create temp files next to the target (tempfile.NamedTemporaryFile(dir=target_dir)).

All Python for DevOps questions Roadmap: Python for automation

More on Runtime, file, subprocess & encoding errors