如果我有一些函数,它做了很多计算,并且可能需要一段时间,那么asyncio.sleep()在计算的各个部分之间使用释放事件循环(以防止阻塞事件循环)是否好?
import asyncio
async def long_function(a, b, c):
# some calculations
await asyncio.sleep(0) # release event loop
# some another calculations
await asyncio.sleep(0) # release event loop
Run Code Online (Sandbox Code Playgroud)
是否有另一种更好的方法来解决此类问题?一些最佳实践,也许?