日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python 异步执行多个函数_Python的asyncio模块写多个异步的执行顺序和影响?

發(fā)布時間:2023/12/15 python 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 异步执行多个函数_Python的asyncio模块写多个异步的执行顺序和影响? 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

寫了小爬蟲,用到asyncio做異步,多次調(diào)用async with 和 await爬蟲操作,但是在其中沒調(diào)用異步的數(shù)據(jù)庫操作沒有成功,代碼下:

async with session.get(restaurant_url) as restaurant_rep:

restaurant_rep = await restaurant_rep.json()

rating_url = RES_URL.format(restaurant_id=restaurant_id)

async with session.get(rating_url) as rating_rep:

rating_rep = await rating_rep.json()

overall_rating, service_rating, food_rating = format_rating_data(rating_rep)

add_restaurant_data(restaurant_rep, overall_rating, service_rating, food_rating)

food_url = constants.ELE_FOOD_JSON.format(restaurant_id=restaurant_id)

async with session.get(food_url) as food_rep:

food_rep = await food_rep.json()

for food_type in food_rep:

for food in food_type['foods']:

food_id = food['specfoods'][0]['food_id']

if food_id not in food_set:

food_set.add(food_id)

add_food_data(food)

add_*函數(shù) 解析response并寫入數(shù)據(jù)庫, 但是8行寫操作并沒有寫成功, 函數(shù)沒問題, 19行寫數(shù)據(jù)庫操作可以,求問一下為什么

順便問一下這樣寫有什么不好?

總結

以上是生活随笔為你收集整理的python 异步执行多个函数_Python的asyncio模块写多个异步的执行顺序和影响?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。