我的代码遵循APScheduler Docs中的示例,但我将其格式更改为遵循我的格式。它没有问题。 “Hello World”每10秒打印一次。
#! /usr/bin/python
import datetime
from apscheduler.schedulers.blocking import BlockingScheduler
class Class1:
def job_function():
print("Hello World")
class Class2:
def go():
sched = BlockingScheduler()
# Schedule job_function to be called every 10 seconds
sched.add_job(Classy.job_function, 'interval', seconds = 10)
sched.start()
if __name__ == '__main__':
Class2.go()
然而,我的实际代码效果并不好。
#! /usr/bin/python
import time
import praw
import OAuth2Util
import redditNewsBot
import redditFreeGameBot
import redditWorldNewsBot
from datetime import datetime
from apscheduler.schedulers.blocking import BlockingScheduler
class Aggregate:
def aggr()
...
def x():
print('x')
class RunSchedule:
def go():
sched = BlockingScheduler()
# Schedule job_function to be called every ten seconds
sched.add_job(Aggregate.x, 'interval', seconds = 10)
sched.start()
if __name__ == '__main__':
RunSchedule.go()
所有东西都会以指定的间隔运行,但我先得到了所有这些:
C:\Users\Nick\AppData\Local\Programs\Python\Python35-32\lib\importlib\_bootstrap_external.py:415: ImportWarning: Not importing directory
C:\Users\Nick\AppData\Local\Programs\Python\Python35-32\lib\site-packages\mpl_toolkits: missing __init___warnings.warn(msg.format(portions[0]), ImportWarning)
C:\Users\Nick\AppData\Local\Programs\Python\Python35-32\lib\importlib\_bootstrap_external.py:415: ImportWarning: Not importing directory
c:\users\nick\appdata\local\programs\python\python35-32\lib\site-packages\mpl_toolkits: missing __init___warnings.warn(msg.format(portions[0]), ImportWarning)
C:\Users\Nick\AppData\Local\Programs\Python\Python35-32\lib\importlib\_bootstrap_external.py:415: ImportWarning: Not importing directory
C:\Users\Nick\AppData\Local\Programs\Python\Python35-32\lib\site-packages\zope: missing __init___warnings.warn(msg.format(portions[0]), ImportWarning)
答案 0 :(得分:0)
那是praw
。
我已将其导入datetime
和from apscheduler.schedulers.blocking import BlockingScheduler
后面的测试脚本,并且无误运行。
然后我把它移到了后者之前,它抛出了错误。
为了从apscheduler.schedulers.blocking import BlockingSchedulerhad
运行无错误,移动到导入列表的最前面。 time
和datetime
也可以没有错误。
from apscheduler.schedulers.blocking import BlockingScheduler
import praw
import time
import datetime
import OAuth2Util
import redditNewsBot
import redditFreeGameBot
import redditWorldNewsBot