code: def testMultiThreadedStacks(self):
      # Instrument for the main thread.
      instrument_0 = _NumpyFunctionCallback()
  
      # Instrument for the to-be-created thread.
      instrument_1 = _NumpyFunctionCallback()
  
      def thread1_job():
          op_callbacks.add_op_callback(instrument_1.callback)
  
          @def_function.function
          def func1(x):
              return math_ops.sqrt(math_ops.log(x))
  
          x = constant_op.constant(4.0)
          self.assertAllClose(func1(x), np.sqrt(np.log(4.0)))
  
      thread1 = threading.Thread(target=thread1_job)
  
      # Start job on separate thread.
      thread1.start()
  
      # Run something on the main thread.
      op_callbacks.add_op_callback(instrument_0.callback)
  
      @def_function.function
      def func0(x):
          return math_ops.square(math_ops.sin(x))
  
      x = constant_op.constant(4.0)
      self.assertAllClose(func0(x), np.square(np.sin(4.0)))
  
      thread1.join()
  
      # Assert that there is no cross-talk between the main thread
      # and the created thread.
      self.assertIn(_PLACEHOLDER_OP, instrument_1.graph_op_types)
      self.assertIn(_LOG_OP, instrument_1.graph_op_types)
      self.assertIn(_SQRT_OP, instrument_1.graph_op_types)
      self.assertNotIn(_SIN_OP, instrument_1.graph_op_types)
      self.assertNotIn(_SQUARE_OP, instrument_1.graph_op_types)
  
      self.assertNotIn(_LOG_OP, instrument_0.graph_op_types)
      self.assertNotIn(_SQRT_OP, instrument_0.graph_op_types)
      self.assertIn(_SIN_OP, instrument_0.graph_op_types)
      self.assertIn(_SQUARE_OP, instrument_0.graph_op_types)
  
imports: import threading
  import numpy
  from tensorflow.python.data.ops import dataset_ops
  from tensorflow.python.eager import backprop
  from tensorflow.python.eager import context
  from tensorflow.python.eager import def_function
  from tensorflow.python.eager import test
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import op_callbacks
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import sparse_tensor
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import control_flow_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import script_ops
  from tensorflow.python.ops import sparse_ops
  from tensorflow.python.ops import variables
  from tensorflow.python.util import compat
label_desc: Use image node_id 3 for calling the OpCallbacksTest obj's underlying member method code with example usage: obj.testMultiThreadedStacks() and returns: math_ops, math_ops