# tf.compat.v1.executing_eagerly

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/eager/context.py#L2311-L2371) |

Checks whether the current thread has eager execution enabled.

    tf.compat.v1.executing_eagerly()

Eager execution is typically enabled via
[`tf.compat.v1.enable_eager_execution`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/compat/v1/enable_eager_execution), but may also be enabled within the
context of a Python function via tf.contrib.eager.py_func.

When eager execution is enabled, returns `True` in most cases. However,
this API might return `False` in the following use cases.

- Executing inside [`tf.function`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/function), unless under [`tf.init_scope`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/init_scope) or [`tf.config.run_functions_eagerly(True)`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/config/run_functions_eagerly) is previously called.
- Executing inside a transformation function for `tf.dataset`.
- [`tf.compat.v1.disable_eager_execution()`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/compat/v1/disable_eager_execution) is called.

    tf.compat.v1.enable_eager_execution()

#### General case:

    print(tf.executing_eagerly())
    True

Inside [`tf.function`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/function):

    @tf.function
    def fn():
      with tf.init_scope():
        print(tf.executing_eagerly())
      print(tf.executing_eagerly())
    fn()
    True
    False

Inside [`tf.function`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/function)
after [`tf.config.run_functions_eagerly(True)`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/config/run_functions_eagerly) is called:

    tf.config.run_functions_eagerly(True)
    @tf.function
    def fn():
      with tf.init_scope():
        print(tf.executing_eagerly())
      print(tf.executing_eagerly())
    fn()
    True
    True
    tf.config.run_functions_eagerly(False)

Inside a transformation function for `tf.dataset`:

    def data_fn(x):
      print(tf.executing_eagerly())
      return x
    dataset = tf.data.Dataset.range(100)
    dataset = dataset.map(data_fn)
    False

<br />

<br />

<br />

| ## Returns ||
|---|---|
| `True` if the current thread has eager execution enabled. ||

<br />