我正在尝试实现在 Heroku dyno 中使用的时钟过程。我正在使用 Python 3.6。时钟进程将每 3 小时运行一次。这是代码:
import os
import sys
import requests
from apscheduler.schedulers import asyncio
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from apscheduler.triggers.interval import IntervalTrigger
from webdriverdownloader import GeckoDriverDownloader
from scraper.common import main
def get_driver():
return True
def notify(str):
return True;
if __name__ == '__main__':
scheduler = AsyncIOScheduler()
get_driver()
scheduler.add_job(main, trigger=IntervalTrigger(hours=3))
scheduler.start()
# Execution will block here until Ctrl+C (Ctrl+Break on Windows) is pressed.
try:
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait())
except (KeyboardInterrupt, SystemExit):
pass
起初我尝试过
asyncio.get_event_loop().run_forever()
但是,我读到这在 python 3.6 中不受支持,所以我将此语句更改为run_until_complete
.
如果我运行这个例子,代码会打印出来:
AttributeError:模块“apscheduler.schedulers.asyncio”没有属性“get_event_loop”
有谁知道为什么会发生这个错误?任何帮助将非常感激。提前致谢!