code: def patch_fork(cls, task):
      cls._current_task = task
      if not task:
          return
  
      # first we need to patch regular fork
      # because forked processes do not support atexit, they call os._exit directly)
  
      # noinspection PyBroadException
      try:
          # only once
          if cls._registered_fork_callbacks or cls._original_fork:
              return
          try:
              os.register_at_fork(
                  before=PatchOsFork._fork_callback_before,
                  after_in_child=PatchOsFork._fork_callback_after_child,
              )
              cls._registered_fork_callbacks = True
          except Exception:
              # python <3.6
              if six.PY2:
                  cls._original_fork = staticmethod(os.fork)
              else:
                  cls._original_fork = os.fork
              os.fork = cls._patched_fork
  
      except Exception:
          pass
  
      # now we need to patch Process.run because the bootstrap code
      # shuts everything down before calling os._exit that we patched above
      try:
          from multiprocessing.process import BaseProcess
  
          PatchOsFork._original_process_run = BaseProcess.run
          BaseProcess.run = PatchOsFork._patched_process_run
      except:  # noqa
          pass
  
imports: import os
  from functools import partial
  from time import sleep
  from multiprocessing import pool
  import six
  from ..config import TASK_LOG_ENVIRONMENT, running_remotely, config
  from ..utilities.process.mp import BackgroundMonitor
label_desc: Use image node_id 1 for calling the PatchOsFork obj's underlying member method code with example usage: obj.patch_fork(cls, task) without return types