asyncio和aiohttp攜程併發

 

import asyncio
from aiohttp import web
import time

async def process():

    for i in range(10):
        print("process data !!")
        # time.sleep(1)
        await asyncio.sleep(1)


async def hello(request):

    job = process()
    asyncio.create_task(job)
    return web.Response(text='Hello Aiohttp!')


app = web.Application()
app.router.add_get("/hello",hello)
web.run_app(app, host="0.0.0.0", port=9000)

  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章