示例
结合一下nodejs的async和golang的goroutine,python的真的很简单。
import threading
import asyncio
import time
async def hello():
print('Hello world! (%s)' % threading.currentThread())
await test()
print('Hello again! (%s)' % threading.currentThread())
async def test():
time.sleep(2)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
tasks = [hello()]
loop.run_until_complete(asyncio.wait(tasks))
loop.close()
网友评论