多线程多Stream
调用接口后,需增加异常处理的分支,并记录报错日志、提示日志,此处不一一列举。以下是关键步骤的代码示例,不可以直接拷贝运行,仅供参考。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import acl # ...... def run_thread(stream): device_id = 0 stream, ret = acl.rt.create_stream() # 调用触发任务的接口。 # .... # 释放资源。 ret = acl.rt.destroy_stream(stream) # 创建2个线程,每个线程对应一个Stream。 thread_id1, ret = acl.util.start_thread(run_thread, stream1) thread_id2, ret = acl.util.start_thread(run_thread, stream2) # 显式调用join函数确保结束线程。 ret = acl.util.stop_thread(thread_id1) ret = acl.util.stop_thread(thread_id2) |
父主题: Stream管理