线程池结合asyncio

  • A+
所属分类:Python基础

使用多线程:在协程中集成阻塞io(比如MySQLdb就是阻塞的)

loop = asyncio.get_event_loop()

from concurrent.futures import ThreadPoolExecutor

executor = ThreadPoolExecutor()

tasks = []

task = loop.run_in_executor(executor,get_url,'http://www.rapfan.cn')

tasks.append(task)

loop.run_until_complete(aysncio.wait(tasks))

  • 微信
  • 等你哟
  • weinxin
  • 微信公众号
  • mac软件资源等你来拿
  • weinxin
小羊同学

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: