简体   繁体   中英

async apscheduler does not start the task

Trying to create a scheduler:

sheduler = AsyncIOScheduler(timezone='Europe/Moscow')

async def thread_maintaining_communication():
    print('There')

async def main():
    sheduler.add_job(thread_maintaining_communication,"interval", seconds=20)
    sheduler.start()
    #await bot.infinity_polling(skip_pending=True)
    while True:
        print('sleep 10 sec')
        await asyncio.sleep(10)

asyncio.run(main())

But for some reason unknown to me, it does not work. Here's what's in the console:

INFO:apscheduler.scheduler:Adding job tentatively -- it will be properly scheduled when the scheduler starts
INFO:apscheduler.scheduler:Added job "thread_maintaining_communication" to job store "default"
sleep 10 secINFO:apscheduler.scheduler:Scheduler started

sleep 10 sec
sleep 10 sec
sleep 10 sec

I was given an answer, I hope that someone who faces the same problem will find this topic

sheduler.add_job(thread_maintaining_communication,"interval", seconds=20)
bot.add_custom_filter(asyncio_filters.StateFilter(bot))
sheduler.start()
loop = asyncio.get_event_loop() 
loop.run_until_complete(bot.polling(skip_pending=True))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM