code: def test_safe_copy_target_file_changes_during_copy(
      tmp_path: Path, monkeypatch
  ):
      source_path = tmp_path / "source.txt"
      target_path = tmp_path / "target.txt"
      source_content = "Source content 📝" * 1000
      changed_target_content = "Changed target content 🔀"
  
      source_path.write_text(source_content, encoding="utf-8")
  
      def repeatedly_write_content():
          end_time = time.time() + 1.0
          while time.time() < end_time:
              try:
                  target_path.write_text(
                      changed_target_content, encoding="utf-8"
                  )
              except PermissionError:
                  pass
  
      def delayed_copy_with_pause(src, dst, *args, **kwargs):
          """Write a 4096 byte block at a time, pausing 0.1 seconds between writes."""
          # Windows often doesn't allow opening a file for writing while there is an open
          # file handle to it. To get around the PermissionError, we close the file
          # between writes, but also retry failed writes.
          pos = 0
          with open(src, "rb") as infile:
              for block in iter(lambda: infile.read(4096), b""):
                  success = False
                  while not success:
                      time.sleep(0.1)
                      try:
                          with open(dst, "wb") as outfile:
                              outfile.seek(pos)
                              outfile.write(block)
                          pos += len(block)
                          success = True
                      except PermissionError:
                          pass
  
      monkeypatch.setattr(shutil, "copy2", delayed_copy_with_pause)
  
      with ThreadPoolExecutor(max_workers=2) as executor:
          future = executor.submit(repeatedly_write_content)
          safe_copy(source_path, target_path)
          future.result()
  
      result_content = target_path.read_text("utf-8")
      assert (
          result_content == source_content
          or result_content == changed_target_content
      )
  
imports: import ctypes
  import errno
  import os
  import platform
  import re
  import shutil
  import sys
  import tempfile
  import time
  from concurrent.futures import ThreadPoolExecutor
  from pathlib import Path
  from unittest import mock
  from unittest.mock import Mock, patch
  import pytest
  from wandb.sdk.lib import filesystem
  from wandb.sdk.lib.filesystem import check_exists, copy_or_overwrite_changed, mkdir_allow_fallback, mkdir_exists_ok, reflink, safe_copy, safe_open, system_preferred_path
label_desc: Use image node_id 25 for calling a global function with example usage: test_safe_copy_target_file_changes_during_copy(tmp_path, monkeypatch) without return types