# tf_agents.policies.async_policy_saver.AsyncPolicySaver

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/policies/async_policy_saver.py#L24-L151) |

Triggers `policy_saver` save calls in a separate thread asynchronously.

    tf_agents.policies.async_policy_saver.AsyncPolicySaver(
        policy_saver: https://www.tensorflow.org/agents/api_docs/python/tf_agents/policies/PolicySaver
    )

<br />

<br />

<br />

| ## Args ||
|---|---|
| `policy_saver` | An instance of a [`policy_saver.PolicySaver`](https://www.tensorflow.org/agents/api_docs/python/tf_agents/policies/PolicySaver). |

<br />

## Methods

### `close`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/policies/async_policy_saver.py#L139-L147)

    close()

Blocks until there is no saving happening and kills the save_thread.

### `flush`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/policies/async_policy_saver.py#L132-L137)

    flush()

Blocks until there is no saving happening.

### `save`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/policies/async_policy_saver.py#L71-L87)

    save(
        export_dir: Text, blocking: bool = False
    )

Triggers an async save of the policy to the given `export_dir`.

Only one save can be triggered at a time. If `save` or `save_checkpoint`
are called while another save of either kind is still ongoing the saving is
skipped.

If blocking is set then the call will block until any ongoing saves finish,
and then a new save will be made before returning.

<br />

<br />

<br />

| Args ||
|---|---|
| `export_dir` | Directory path for the `saved_model` of the policy. |
| `blocking` | If True the call to save will block until a save can be performed and finished. If a save was ongoing it will wait for that to finish, and then do a blocking save before returning. |

<br />

### `save_checkpoint`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/policies/async_policy_saver.py#L89-L105)

    save_checkpoint(
        export_dir: Text, blocking: bool = False
    )

Triggers an async save of the policy checkpoint.

Only one save can be triggered at a time. If `save` or `save_checkpoint`
are called while another save of either kind is still ongoing the saving is
skipped.

If blocking is set then the call will block until any ongoing saves finish,
and then a new save will be made before returning.

<br />

<br />

<br />

| Args ||
|---|---|
| `export_dir` | Directory path for the checkpoint of the policy. |
| `blocking` | If True the call to save will block until a save can be performed and finished. If a save was ongoing it will wait for that to finish, and then do a blocking save before returning. |

<br />