code: def atomic_write(dst_path):
      """A context manager to simplify atomic writing.
  
      Usage:
      >>> with atomic_write(dst_path) as tmp_path:
      >>>     # write to tmp_path
      >>> # Here tmp_path renamed to dst_path, if no exception happened.
      """
      tmp_path = str(dst_path) + ".tmp"
      try:
          yield tmp_path
      except:
          if os.path.exists(tmp_path):
              os.remove(tmp_path)
          raise
      else:
          # If everything is fine, move tmp file to the destination.
          shutil.move(tmp_path, str(dst_path))
  
imports: import contextlib
  import json
  import os
  import shutil
  from datetime import datetime
  import numpy
  import pandas
  from imageio import imwrite
  from tensorboard.compat.proto.event_pb2 import Event
  from tensorboard.compat.proto.event_pb2 import SessionLog
  from torch.utils.tensorboard import SummaryWriter, FileWriter
label_desc: Use image node_id 1 for calling a global function with example usage: atomic_write(dst_path) without return types