« Back to Index

Python Asyncio Loop Forever

View original Gist on GitHub

loop forever.py

import asyncio

async def listener():
    while True:
        message = await sqs.poll()
        if message:
            asyncio.ensure_future(handle(message))
            
async def handler(message):
    await ...

loop = asyncio.get_event_loop()
asyncio.ensure_future(listener)
loop.run_forever()