如何为循环中的每个序列 运行 asyncio 调度程序?

How to run asyncio scheduler for each sequence in a loop?

我有一个 job scheduler 已经作为下面的脚本工作,还有一个 cycle 实现 运行 每个 app 的几个函数。但是,一旦 scheduler 命中适当的时间,它 运行 仅在可用的 app.

正在安排作业:

scheduler.add_job(refresh_hereoes_positions, 'interval', seconds=(refresh_heroes_time*60), id='1', name='refresh_hereoes_positions', misfire_grace_time=180)

循环:

bots = []
for app in applications:
    bot = app.split(':')[1].strip()
    print('Going to bot: ' + str(bot))
    app = Desktop(backend="uia").windows(title=app)[0]
    app.set_focus()
    await asyncio.create_task(first_start(app_name=bot))
    bots.append((app, bot))

# Cycle through the bots in one loop rather than restarting
# the loop in an infinite loop.
for app, bot in cycle(bots):
    print('Going to bot: ' + str(bot))
    app.set_focus()
    await asyncio.create_task(connect_wallet(app_name=bot))
    await asyncio.create_task(login_metamask(app_name=bot))
    await asyncio.create_task(treasure_hunt_game(refresh_only=True, app_name=bot))
    await asyncio.create_task(new_map(app_name=bot))
    await asyncio.create_task(skip_error_on_game(app_name=bot))

如何在 cycle 中为每个 app 触发 运行 job

我能够 运行 通过创建 class SetTrigger:

cycle 中每个 app 的函数
class SetTrigger(object):
    def __init__(self):
        self.set_work = False
        self.set_reload = False
        self.set_refresh = False
        self.set_coin = False
    
    def UpdateSetRefresh(self):
        self.set_refresh = True
        return self.set_refresh

    def UpdateSetWork(self):
        self.set_work = True
        return self.set_work

    def UpdateSetReload(self):
        self.set_reload = True
        return self.set_reload
    
    def UpdateSetCoin(self):
        self.set_coin = True
        return self.set_coin

之后,我在 main.py 中调用 class:

trigger = SetTrigger()

scheduler.add_job(trigger.UpdateSetRefresh, 'interval', minutes=refresh_ships_time, id='1', name='refresh_game', misfire_grace_time=180)

for app in cycle(applications):
    ...

    # Here I'm calling the function refresh_game
    if trigger.set_refresh != False:
        if app[1] not in bot_executions_refresh:
            bot_executions_refresh.append(app[1])
            await asyncio.create_task(refresh_game(app_name=app[1]))

    # - Reset trigger to call functions from schedule
    if (len(bot_executions_refresh) == len(applications)) and trigger.set_refresh != False:
        bot_executions_refresh.clear()
        trigger.set_refresh = False

有关详细信息,可以在我的 repository.

上找到解决方案