code: def avoid_concurrent_lock_cls(cls):
      """Wraps a function to lock a filelock for concurrent access with the name of the class to which it applies, to avoid deadlocks
      :param cls: the class to which is applied, only when the class corresponds to the instance type, this filelock will apply
      :return: the wrapped function
      """
  
      def avoid_concurrent_lock_wrapper(func: Callable) -> Callable:
          """Wrap the function around a File Lock to make sure that the function is run by a single replica in the same machine
          :param func: the function to decorate
          :return: the wrapped function
          """
  
          @functools.wraps(func)
          def arg_wrapper(self, *args, **kwargs):
              if func.__name__ != "__init__":
                  raise TypeError(
                      "this decorator should only be used on __init__ method of an executor"
                  )
  
              if self.__class__ == cls:
                  with ImportExtensions(
                      required=False,
                      help_text=f"FileLock is needed to guarantee non-concurrent initialization of replicas in the "
                      f"same machine.",
                  ):
                      import filelock
  
                      locks_root = _get_locks_root()
  
                      lock_file = locks_root.joinpath(
                          f"{self.__class__.__name__}.lock"
                      )
  
                      file_lock = filelock.FileLock(
                          lock_file, timeout=-1
                      )
  
                  with file_lock:
                      f = func(self, *args, **kwargs)
                  return f
              else:
                  return func(self, *args, **kwargs)
  
          return arg_wrapper
  
      return avoid_concurrent_lock_wrapper
  
file_path: jina/jina/serve/executors/decorators.py
imports: import functools
  import inspect
  import os
  from pathlib import Path
  from typing import Callable, Dict, List, Optional, Sequence, Type, Union
  from jina._docarray import Document, DocumentArray, docarray_v2
  from jina.constants import __cache_path__
  from jina.helper import is_generator, iscoroutinefunction
  from jina.importer import ImportExtensions
label_desc: Use image node_id 2 for calling a global function with example usage: avoid_concurrent_lock_cls(cls) and returns: avoid_concurrent_lock_wrapper, arg_wrapper, f, func