异步 vs 同步
同步(Synchronous)
异步(Asynchronous)
总结
特性
同步编程(Synchronous Programming)
异步编程(Asynchronous Programming)
示例代码
总结
Last updated
Last updated
def fetch_data():
data = get_data_from_server() # 阻塞,直到返回数据
process_data(data)
print("Data processed.")import asyncio
async def fetch_data():
data = await get_data_from_server() # 非阻塞
process_data(data)
print("Data processed.")
asyncio.run(fetch_data())