code: def ensure_dir_exists(path, mode=0o755):
      """ensure that a directory exists
  
      If it doesn't exist, try to create it and protect against a race condition
      if another process is doing the same.
  
      The default permissions are 755, which differ from os.makedirs default of 777.
      """
      if not os.path.exists(path):
          try:
              os.makedirs(path, mode=mode)
          except OSError as e:
              if e.errno != errno.EEXIST:
                  raise
      elif not os.path.isdir(path):
          raise IOError("%r exists but is not a directory" % path)
  
imports: import os
  import sys
  import errno
  import shutil
  import random
  import glob
  from IPython.utils.process import system
label_desc: Use image node_id 16 for calling a global function with example usage: ensure_dir_exists(path, mode) without return types