应用异步 Sleep 的代码:
- import asyncio
- import time
- from datetime import datetime
- async def custom_sleep():
- print('SLEEP {}\n'.format(datetime.now()))
- await asyncio.sleep(1)
- async def factorial(name, number):
- f = 1
- for i in range(2, number+1):
- print('Task {}: Compute factorial({})'.format(name, i))
- await custom_sleep()
- f *= i
- print('Task {}: factorial({}) is {}\n'.format(name, number, f))
- start = time.time()
- loop = asyncio.get_event_loop()
- tasks = [
- asyncio.ensure_future(factorial("A", 3)),
- asyncio.ensure_future(factorial("B"
推荐阅读
让我们先看一下 kdump 的根本应用办法,和 kdump/kexec 在内核中是若何实现。kdump 是获取崩溃的 Linux 内核转储的一种办法,然则想找到解释其应用和内部构造的文档可能有点艰苦。在本文中>>>详细阅读
本文标题:Python中的异步编程:Asyncio
地址:http://www.17bianji.com/lsqh/36515.html
1/2 1

网友点评
精彩导读
科技快报
品牌展示