这是一个创建于 1438 天前的主题,其中的信息可能已经有所发展或是发生改变。
由于看到有 `async for` 和 `for await `,所以不清楚如果 task_list 是一个比较长的 list 是否会阻塞呢?找了一圈谷歌没有说到这个的...
```python
async def func():
____task_list = list()
____for task in tasks.task_list:
________status= await redis_client.get(f'task:{task}')
```
2 条回复 • 2020-10-31 04:27:16 +08:00
|
|
1
fasionchan 2020-10-30 13:11:12 +08:00
不会,如果子任务阻塞的话,await 会让出执行权
|
|
|
2
black11black 2020-10-31 04:27:16 +08:00
取决于你调用方法内部是否有把控制权返回的命令。一个异步函数,内部如果没有任何异步调用,过程中即使 await 也是不会向 eventloop 返回的,也就是说执行时阻塞。
|