异步调用(坑)

异步调用(坑)

from concurrent.futures import ThreadPoolExecutor

executor = ThreadPoolExecutor(5)

def review():
'''省略过程'''

异步提交任务

executor.submit(call_crawl, country, 'rv')
return

def call_crawl(country, type):
#这样写会阻塞,导致上面的review函数不能立即return
os.system('/home/hblyl/hb_crawl/amz_uk/run_task.sh')
#需要这样写
os.system('/home/hblyl/hb_crawl/amz_uk/run_task.sh &')

说明:os.system()是阻塞状态的,即使调用者异步执行也不行
所以需要把命令结尾加上 &让脚本在后台运行

posted @ 2020-12-09 14:21  rm-rf*  阅读(115)  评论(0)    收藏  举报