code: def calc_md5_with_blocking_retries(
      path: str,
      *,  # keyword-only arguments:
      glob_pattern: Optional[str] = None,
      allow_nonexistent: bool = False,
  ) -> str:
      """Calculate the MD5 checksum of a given path.
  
      For a file, this means calculating the md5 of the file's contents. For a
      directory, we concatenate the directory's path with the names of all the
      files in it and calculate the md5 of that.
  
      IMPORTANT: This method calls time.sleep(), which blocks execution. So you
      should only use this outside the main thread.
      """
  
      if allow_nonexistent and not os.path.exists(path):
          content = path.encode("UTF-8")
      elif os.path.isdir(path):
          glob_pattern = glob_pattern or "*"
          content = _stable_dir_identifier(path, glob_pattern).encode(
              "UTF-8"
          )
      else:
          content = _get_file_content_with_blocking_retries(path)
  
      md5 = hashlib.md5(**HASHLIB_KWARGS)
      md5.update(content)
  
      # Use hexdigest() instead of digest(), so it's easier to debug.
      return md5.hexdigest()
  
file_path: streamlit/lib/streamlit/watcher/util.py
imports: import hashlib
  import os
  import time
  from pathlib import Path
  from typing import Optional
  from streamlit.util import HASHLIB_KWARGS
label_desc: Use image node_id 1 for calling a global function with example usage: calc_md5_with_blocking_retries(path) and returns: md5