mardi 3 mars 2020

what's the order if there are two asyncio.get_event_loop?

There are two things need to be done: host website and send notification.So I use the following ways to solve this problems:

from aiohttp import web
import asyncio


async def _send_proactive_message():
    ...

async def pre_init():
    await asyncio.sleep(20)
    await _send_proactive_message()

APP = web.Application()
APP.router.add_post("/api/messages", messages)
APP.router.add_get("/api/notify", notify)




if __name__ == '__main__':


    event_loop = asyncio.get_event_loop()
    try:
        event_loop.create_task(pre_init())
        web.run_app(APP, host="localhost", port=CONFIG.PORT)

    finally:
        event_loop.close()

because there is one event_loop in web.run_app, I don't understand which one run first and how to control every event_loop. please help me.




Aucun commentaire:

Enregistrer un commentaire