P.Alipoor
P.Alipoor

Reputation: 178

Multiple asyncio loops

I am implementing a service in a multi-service python application. This service will wait for requests to be pushed in a redis queue and resolve them whenever one is available.

async def foo():
    while True:
        _, request = await self.request_que.brpop(self.name)
        # processing request ...

And I'm adding this foo() function to an asyncio event loop:

loop = asyncio.new_event_loop()
asyncio.ensure_future(self.handle(), loop=loop)
loop.run_forever()

The main question is, is it ok to do this on several(say 3 or 4) different services, that results in running several asyncio loops simultaneously? Will it harm OS?

Upvotes: 0

Views: 1697

Answers (1)

Torsten Engelbrecht
Torsten Engelbrecht

Reputation: 13486

Simple answer: yes. It is fine. I previously implemented a service which runs on one asyncio loop and spawns additional processes which run on their own loop (within the same machine).

Upvotes: 2

Related Questions