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()是阻塞状态的,即使调用者异步执行也不行
所以需要把命令结尾加上 &
让脚本在后台运行
原文:https://www.cnblogs.com/lyalong/p/14108319.html