
举个例子,有一个列表[1,2,3,……,m] 如何让他一次“同时”输出 n 个? 比如 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 下面这个要输出几次,就创建几个实例的写法感觉太笨了,也不好维护,有没有灵活的方法? 当然,这个例子有点傻,因为执行过的没必要再执行一次。实际情况应该是如何根据队列灵活的调整执行速度。 import asyncio li = [1,2,3,4,5,6,7,8,9,10] def hello(): for i in li: print(str(i)+"\n") async def main(): loop = asyncio.get_event_loop() future1 = loop.run_in_executor(None, hello) future2 = loop.run_in_executor(None, hello) future3 = loop.run_in_executor(None, hello) await future1 await future2 await future3 loop = asyncio.get_event_loop() loop.run_until_complete(main()) 1 Septembers 2017-01-25 06:11:25 +08:00 via iPhone 令牌桶? |
2 Lemon23 2017-02-09 15:55:53 +08:00 楼主后来怎么解决的? |