Skip to main content

8、协程

Y-aong...About 1 minpython协程

8、协程

详情还是要看文档

run()open in new window创建事件循环,运行一个协程,关闭事件循环。
Runneropen in new windowA context manager that simplifies multiple async function calls.
Taskopen in new windowTask对象
TaskGroupopen in new windowA context manager that holds a group of tasks. Provides a convenient and reliable way to wait for all tasks in the group to finish.
create_task()open in new windowStart an asyncio Task, then returns it.
current_task()open in new window返回当前Task对象
all_tasks()open in new windowReturn all tasks that are not yet finished for an event loop.
await sleep()open in new window休眠几秒。
await gather()open in new window并发执行所有事件的调度和等待。
await wait_for()open in new window有超时控制的运行。
await shield()open in new window屏蔽取消操作
await wait()open in new window完成情况的监控器
timeout()open in new windowRun with a timeout. Useful in cases when wait_for is not suitable.
to_thread()open in new window在不同的 OS 线程中异步地运行一个函数。
run_coroutine_threadsafe()open in new window从其他OS线程中调度一个协程。
for in as_completed()open in new windowfor 循环监控完成情况。

事件循环

所以,我们可以想象,现在有一个循环和一个生成器列表,每次循环,我们都将所有的生成器进行一次调用,所有生成器交替执行。

Comments
  • Latest
  • Oldest
  • Hottest
Powered by Waline v2.15.8