code: def test_actor_stdout(file):
      if file == "stdout":
          file_handle = "sys.stdout"
      else:  # sys.stderr
          file_handle = "sys.stderr"
  
      script = f"""
  import ray
  import sys
  
  ray.init(num_cpus=2)
  
  @ray.remote
  class Actor1:
      def f(self):
          print("hi", file={file_handle})
  
  @ray.remote
  class Actor2:
      def __init__(self):
          print("init", file={file_handle})
          self.name = "ActorX"
      def f(self):
          print("bye", file={file_handle})
      def __repr__(self):
          return self.name
  
  a = Actor1.remote()
  ray.get(a.f.remote())
  b = Actor2.remote()
  ray.get(b.f.remote())
      """
  
      proc = run_string_as_driver_nonblocking(script)
      if file == "stdout":
          out_str = proc.stdout.read().decode("ascii")
      else:
          out_str = proc.stderr.read().decode("ascii")
  
      out_str = "".join(out_str.splitlines())
      assert "hi" in out_str, out_str
      assert "(Actor1 pid=" in out_str, out_str
      assert "bye" in out_str, out_str
      assert re.search("Actor2 pid=.*init", out_str), out_str
      assert not re.search("ActorX pid=.*init", out_str), out_str
      assert re.search("ActorX pid=.*bye", out_str), out_str
      assert re.search("Actor2 pid=.*bye", out_str), out_str
  
imports: import os
  import re
  import signal
  import subprocess
  import sys
  import time
  import pytest
  import ray
  from ray._private.test_utils import run_string_as_driver, run_string_as_driver_nonblocking, wait_for_condition
label_desc: Use image node_id 20 for calling a global function with example usage: test_actor_stdout(file) without return types