code: def test_unhandled_errors(ray_start_regular):
      @ray.remote
      def f():
          raise ValueError()
  
      @ray.remote
      class Actor:
          def f(self):
              raise ValueError()
  
      a = Actor.remote()
      num_exceptions = 0
  
      def interceptor(e):
          nonlocal num_exceptions
          num_exceptions += 1
  
      # Test we report unhandled exceptions.
      ray._private.worker._unhandled_error_handler = interceptor
      x1 = f.remote()
      x2 = a.f.remote()
      del x1
      del x2
      wait_for_condition(lambda: num_exceptions == 2)
  
      # Test we don't report handled exceptions.
      x1 = f.remote()
      x2 = a.f.remote()
      with pytest.raises(ray.exceptions.RayError) as err:  # noqa
          ray.get([x1, x2])
      del x1
      del x2
      time.sleep(1)
      assert num_exceptions == 2, num_exceptions
  
      # Test suppression with env var works.
      try:
          os.environ["RAY_IGNORE_UNHANDLED_ERRORS"] = "1"
          x1 = f.remote()
          del x1
          time.sleep(1)
          assert num_exceptions == 2, num_exceptions
      finally:
          del os.environ["RAY_IGNORE_UNHANDLED_ERRORS"]
  
imports: import os
  import signal
  import sys
  import time
  import numpy
  import pytest
  import ray
  import ray._private.gcs_utils
  import ray._private.ray_constants
  import ray._private.utils
  from ray._private.test_utils import SignalActor, convert_actor_state, get_error_message, init_error_pubsub, wait_for_condition
  from ray.exceptions import GetTimeoutError, RayActorError, RayTaskError
label_desc: Use image node_id 1 for calling a global function with example usage: test_unhandled_errors(ray_start_regular) without return types