I am trying to implement clock process to use in Heroku dyno. I am using Python 3.6. Clock process will run each 3 hours. This is the code:
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
At first I tried with
asyncio.get_event_loop().run_forever()
However, I read that this is not supported in python 3.6, so I changed this statement to run_until_complete
.
If I run this example, the code prints out:
AttributeError: module 'apscheduler.schedulers.asyncio' has no attribute 'get_event_loop'
Does anyone know why this error occurs? Any help would be much appreciated. Thanks in advance!
You're not importing the
asyncio
module from the standard library but theasyncio
module in theapscheduler
library. You can see that by visiting the link here.There are only two things you can import from that namespace:
run_in_event_loop
AsyncIOScheduler
If you need to use the low-level
asyncio
API just importasyncio
directly from the standard library.