Использование APSchedule для запуска ожидает в фоновом режиме - PullRequest
0 голосов
/ 30 октября 2018

Я пытаюсь написать Cog на Python3.6 для ветви перезаписи Discord (точнее, версии 1.0.0a), которая проверяет метод await каждый день в полночь. Цель метода check_costume - проверить, следует ли менять аватар бота из файлов в папке. Я проверил, что файлы читаются правильно и что сам метод действительно работает, но APScheduler отказывается использовать backgroundscheduler с asyncio executor. Продолжает возвращать ошибку: Executor lookup ("asyncio") failed for job "CostumeCog.check_costume (trigger: cron[hour='8', minute='15'], next run at: 2018-10-30 08:15:00 CDT)" -- removing it from the job store

Вот винтик:

import os
from datetime import date
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.executors.asyncio import AsyncIOExecutor

class CostumeCog:
    """CostumeCog is a cog that automagically changes the profile picture of Cueball for the holiday."""
    def __init__(self, bot):
        self.bot = bot
        self.sched = BackgroundScheduler()

    async def check_costume(self):
        print("Spook.")
        picture = open('cogs/costumecog/standard.png')
        for file in [f.strip('.png').split('-') for f in os.listdir('cogs/costumecog/costumes/')
                     if os.path.isfile(os.path.join('cogs/costumecog/costumes/', f))]:
            if int(file[0]) <= int(date.today().strftime("%m%d")) <= int(file[2]):
                picture = open(f'{"-".join(file)}.png', 'rb')
        await self.bot.edit_profile(avatar = picture.read())
        print("Costume checked.")

    def start_timer(self):
        self.sched.start()
        self.sched.add_job(self.check_costume, trigger = 'cron', hour = 20, minute = 27, id = 'check_costume', executor = 'asyncio')

def setup(bot):
    CostumeCog(bot).start_timer()
    bot.add_cog(CostumeCog(bot))

print("Spook") отображается только при запуске метода. Любые решения или советы будут с благодарностью.

...