code: def test_atexit_handler(ray_start_regular_shared, exit_condition):
      @ray.remote
      class A:
          def __init__(self, tmpfile, data):
              import atexit
  
              def f(*args, **kwargs):
                  with open(tmpfile, "w") as f:
                      f.write(data)
                      f.flush()
  
              atexit.register(f)
  
          def ready(self):
              pass
  
          def exit(self):
              ray.actor.exit_actor()
  
      data = "hello"
      tmpfile = tempfile.NamedTemporaryFile(
          "w+", suffix=".tmp", delete=False
      )
      tmpfile.close()
  
      a = A.remote(tmpfile.name, data)
      ray.get(a.ready.remote())
  
      if exit_condition == "out_of_scope":
          del a
      elif exit_condition == "__ray_terminate__":
          ray.wait([a.__ray_terminate__.remote()])
      elif exit_condition == "ray.actor.exit_actor":
          ray.wait([a.exit.remote()])
      elif exit_condition == "ray.kill":
          ray.kill(a)
      else:
          assert False, "Unrecognized condition"
  
      def check_file_written():
          with open(tmpfile.name, "r") as f:
              if f.read() == data:
                  return True
              return False
  
      # ray.kill() should not trigger atexit handlers, all other methods should.
      if exit_condition == "ray.kill":
          assert not check_file_written()
      else:
          wait_for_condition(check_file_written)
  
      os.unlink(tmpfile.name)
  
imports: import datetime
  import os
  import random
  import sys
  import tempfile
  import numpy
  import pytest
  import ray
  from ray import cloudpickle
  from ray._private import ray_constants
  from ray._private.test_utils import client_test_enabled, wait_for_condition, wait_for_pid_to_exit
  from ray.actor import ActorClassInheritanceException
  from ray.tests.client_test_utils import create_remote_signal_actor
  from ray._private.test_utils import SignalActor
  import setproctitle
label_desc: Use image node_id 40 for calling a global function with example usage: test_atexit_handler(ray_start_regular_shared, exit_condition) and returns: False, True