---
title: 函数：stream_wait_event
description: "| 产品 | 是否支持 |"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/API/runtimeapi/aclpythondevg_01_0101.html
sourcePath: /source/zh/canncommercial/900/API/runtimeapi/aclpythondevg_01_0101.html
indexId: 98c62ba29fa1c3601b9695c4945283d7acef8662a315fae0d885860ce41f2e8971
---
# 函数：stream_wait_event

#### 产品支持情况

| 产品 | 是否支持 |
| --- | --- |
| Atlas 350 加速卡 | √ |
| Atlas A3 训练系列产品 / Atlas A3 推理系列产品 | √ |
| Atlas A2 训练系列产品 / Atlas A2 推理系列产品 | √ |
| Atlas 训练系列产品 | √ |
| Atlas 推理系列产品 | √ |
| Atlas 200I/500 A2 推理产品 | √ |


#### 功能说明

阻塞指定Stream的运行，直到指定的Event完成，支持多个Stream等待同一个Event的场景。异步接口。

提交到Stream上的所有后续任务都需要等待Event捕获的任务都完成后才能开始执行。具体见acl.rt.record_event接口了解Event捕获的细节。


#### 函数原型

- C函数原型
  1 aclError aclrtStreamWaitEvent(aclrtStream stream, aclrtEvent event)

- python函数
  1 ret = acl.rt.stream_wait_event(stream, event)


#### 参数说明

| 参数名 | 说明 |
| --- | --- |
| stream | int，指定需要等待Event完成的Stream的指针地址。如果使用默认Stream，此处设置为0。 |
| event | int，需等待的Event的指针地址。 |


#### 返回值说明

| 返回值 | 说明 |
| --- | --- |
| ret | int，错误码，返回0表示成功，返回其它值表示失败。 |


#### 约束说明

- 该接口是异步接口，调用接口成功仅表示任务下发成功，不表示任务执行成功。调用该接口后，需调用同步等待接口（例如，  acl.rt.synchronize_stream
）确保任务已执行完成。
-   acl.rt.record_event
接口与  acl.rt.stream_wait_event
接口配合使用时，主要用于多Stream之间同步的场景，在调用  acl.rt.record_event
接口时，系统内部会申请Event资源，在调用  acl.rt.stream_wait_event
接口之后，请及时调用  acl.rt.reset_event
接口释放Event资源。
  接口调用顺序：acl.rt.create_event-->acl.rt.record_event-->acl.rt.stream_wait_event-->acl.rt.reset_event

- 一个进程内，调用  acl.init
接口初始化后，调用  acl.rt.set_op_wait_timeout
接口设置超时时间，本进程内后续调用  acl.rt.stream_wait_event
接口下发的任务支持在所设置的超时时间内等待，若等待的时间超过所设置的超时时间，则会返回报错。
  由于acl.rt.stream_wait_event接口是异步接口，调用接口成功仅表示任务下发成功，不表示任务执行成功，因此若等待的时间超过所设置的超时时间，则在调用acl.rt.synchronize_stream接口后，会返回报错。


#### 资源参考

接口调用示例，参见关于Event的同步等待(https://www.hiascend.comdocument/detail/zh/canncommercial/900/programug/acldevg/aclpythondevg_0024.html)、关于Stream间任务的同步等待（通过Event实现）(https://www.hiascend.comdocument/detail/zh/canncommercial/900/programug/acldevg/aclpythondevg_0026.html)。
