# tf.compat.v1.train.MonitoredSession.StepContext

<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/training/monitored_session.py#L840-L875) |

Control flow instrument for the `step_fn` from `run_step_fn()`.

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.train.SingularMonitoredSession.StepContext`](https://www.tensorflow.org/api_docs/python/tf/compat/v1/train/MonitoredSession/StepContext)

<br />

    tf.compat.v1.train.MonitoredSession.StepContext(
        session, run_with_hooks_fn
    )

Users of `step_fn` may perform `run()` calls without running hooks
by accessing the `session`. A `run()` call with hooks may be performed
using `run_with_hooks()`. Computation flow can be interrupted using
`request_stop()`.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `session` | An instance of [`tf.compat.v1.Session`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/compat/v1/Session). |
| `run_with_hooks_fn` | A function for running fetches and hooks. |

<br />

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `session` | <br /> <br /> |

<br />

## Methods

### `request_stop`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/training/monitored_session.py#L867-L875)

    request_stop()

Exit the training loop by causing `should_stop()` to return `True`.

Causes `step_fn` to exit by raising an exception.

<br />

<br />

<br />

| Raises ||
|---|---|
| StopIteration ||

<br />

### `run_with_hooks`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/training/monitored_session.py#L863-L865)

    run_with_hooks(
        *args, **kwargs
    )

Same as `MonitoredSession.run`. Accepts the same arguments.