Python基础系列-异步IO
版权声明:如需转载,请注明转载地址。 https://blog.csdn.net/oJohnny123/article/details/81980259 涉及到几个概念: 1、协程是为了解决高并发用的东西。 2、协程的优点:无需线程上下文切换的开销,由此可以提高性能。无需原子操作锁定及同步的开销。也就是说,开销小。 asyncio就是一种异步IO 协程 import threading import asyncio import requests # 把 generator 标记为 coroutine 类型,便于执行 EventLoop @asyncio.coroutine def func(port): result = requests.get('http://10.0.53.129:{0}'.format(port)) print('Start %s! code: %s (%s)' % (port,result.status_code, threading.currentThread())) # 获取 EventLoop loop = asyncio.get_event_loo...