0

I am trying to build a service which runs on a flask server that creates a schedule and runs it continuously to poll data and check results. I'm using apscheduler and AsyncIOS for this. The issue is that I believe my code is creating 2 event loops? which is why I'm continuously getting this error :

cb=[gather.<locals>._done_callback() at /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/tasks.py:764]> **got Future <Future pending> attached to a different loop**

I'm assuming I would have to remove one of those event loops but I'm not sure how

Main:

if __name__ == "__main__":
    init_scheduler()
    import asyncio
    from hypercorn.asyncio import serve
    from hypercorn.config import Config

    async def run_server():
        config = Config()
        config.bind = ["localhost:5000"]
        scheduler.start()
        await serve(app, config)

    asyncio.run(run_server())

Init_scheduler:

def init_scheduler():
    config = load_config('./alert-config.yaml')
    schedule_alerts(config)
    logger.info("Scheduler initialized")

schedule_alerts:

def schedule_alerts(config):
    for alert in config['alerts']:
        job = scheduler.add_job(
            func=check_alert,
            trigger=IntervalTrigger(minutes=alert['interval']),
            args=[alert],
            id=f"alert_{alert['question_id']}"
        )
        logger.info(f"Scheduled job for question ID")

0