code: def temporary_save_path(
      filepath: tp.Union[Path, str]
  ) -> tp.Iterator[Path]:
      """Yields a path where to save a file and moves it
      afterward to the provided location (and replaces any
      existing file)
      This is useful to avoid processes monitoring the filepath
      to break if trying to read when the file is being written.
  
      Note
      ----
      The temporary path is the provided path appended with .save_tmp
      """
      filepath = Path(filepath)
      tmppath = filepath.with_suffix(filepath.suffix + ".save_tmp")
      assert (
          not tmppath.exists()
      ), "A temporary saved file already exists."
      yield tmppath
      if not tmppath.exists():
          raise FileNotFoundError(
              "No file was saved at the temporary path."
          )
      if filepath.exists():
          os.remove(filepath)
      os.rename(tmppath, filepath)
  
imports: import contextlib
  import io
  import itertools
  import os
  import pickle
  import select
  import shutil
  import subprocess
  import sys
  import tarfile
  import typing
  from pathlib import Path
  import cloudpickle
label_desc: Use image node_id 2 for calling a global function with example usage: temporary_save_path(filepath) without return types