code: def test_multiprocess_as_directory(
      checkpoint: Checkpoint, monkeypatch
  ):
      """Tests that deletion lock files are created and deleted correctly,
      when multiple processes are accessing a checkpoint with `as_directory`
      """
      # If this is pointing to a local path, no lockfiles will be created.
      is_local_checkpoint = isinstance(
          checkpoint.filesystem, pyarrow.fs.LocalFileSystem
      )
  
      monkeypatch.setattr(os, "getpid", lambda: 11111)
  
      with checkpoint.as_directory() as checkpoint_dir_1:
          lock_file_1 = Path(_get_del_lock_path(checkpoint_dir_1))
  
          # Pretend that the 2nd `as_directory` is called from a different process.
          monkeypatch.setattr(os, "getpid", lambda: 22222)
  
          with checkpoint.as_directory() as checkpoint_dir_2:
              lock_file_2 = Path(_get_del_lock_path(checkpoint_dir_2))
  
              # Should point both processes to the same canonical temp directory.
              assert checkpoint_dir_1 == checkpoint_dir_2
  
              if is_local_checkpoint:
                  # Check that 2 different lock files were created.
                  assert not lock_file_1.exists()
                  assert not lock_file_2.exists()
              else:
                  # Check that 2 different lock files were created.
                  assert lock_file_1.exists()
                  assert lock_file_2.exists()
  
                  assert (
                      len(_list_existing_del_locks(checkpoint_dir_1))
                      == 2
                  )
  
          if not is_local_checkpoint:
              # Check that the 2nd lock file was deleted.
              assert (
                  len(_list_existing_del_locks(checkpoint_dir_1)) == 1
              )
              assert not lock_file_2.exists()
  
      if not is_local_checkpoint:
          # Check that the 1st lock file was deleted.
          assert len(_list_existing_del_locks(checkpoint_dir_1)) == 0
          assert not lock_file_1.exists()
  
          # Check that the temp checkpoint directory was deleted.
          assert not Path(checkpoint_dir_1).exists()
  
file_path: ray/python/ray/train/tests/test_checkpoint.py
imports: import os
  from pathlib import Path
  import pyarrow.fs
  import pytest
  import ray
  from ray.train._checkpoint import _CHECKPOINT_TEMP_DIR_PREFIX, _METADATA_FILE_NAME, Checkpoint, _get_del_lock_path, _list_existing_del_locks
  from ray.train._internal.storage import _exists_at_fs_path, _upload_to_fs_path
  from ray.train.tests.test_new_persistence import _create_mock_custom_fs
label_desc: Use image node_id 6 for calling a global function with example usage: test_multiprocess_as_directory(checkpoint, monkeypatch) without return types