code: def testGeneratorDatasetFinalizeFunctionCalled(self):
      # NOTE(mrry): This test tests the internal `_GeneratorDataset`,
      # which affords more control over what the finalize function can do than
      # the `Dataset.from_generator()` wrapper.
  
      # Use an `Event` to signal that the generator has been deleted.
      event = threading.Event()
  
      def finalize_fn(_):
          def finalize_py_func():
              event.set()
              return 0
  
          return script_ops.py_func(
              finalize_py_func, [], [dtypes.int64], stateful=True
          )
  
      dummy = constant_op.constant(37)
  
      dataset = from_generator_op._GeneratorDataset(
          dummy,
          lambda x: x,
          lambda x: x,
          finalize_fn,
          tensor_spec.TensorSpec((), dtypes.int32),
      )
  
      dataset = dataset.take(2)
      get_next = self.getNext(dataset)
  
      self.assertAllEqual(37, self.evaluate(get_next()))
      self.assertAllEqual(37, self.evaluate(get_next()))
      with self.assertRaises(errors.OutOfRangeError):
          self.evaluate(get_next())
  
imports: import threading
  from absl.testing import parameterized
  import numpy
  from tensorflow.python.data.kernel_tests import test_base
  from tensorflow.python.data.ops import dataset_ops
  from tensorflow.python.data.ops import from_generator_op
  from tensorflow.python.framework import combinations
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import errors
  from tensorflow.python.framework import sparse_tensor
  from tensorflow.python.framework import tensor_spec
  from tensorflow.python.ops import script_ops
  from tensorflow.python.ops import sparse_ops
  from tensorflow.python.ops.ragged import ragged_factory_ops
  from tensorflow.python.ops.ragged import ragged_tensor
  from tensorflow.python.platform import test
label_desc: Use image node_id 19 for calling the FromGeneratorTest obj's underlying member method code with example usage: obj.testGeneratorDatasetFinalizeFunctionCalled() and returns: script_ops, int