我正在尝试在我的机器人上运行后台任务和命令,我曾尝试使用@tasks.loop(seconds='timehere')
我的后台任务的装饰器。我的任务仅在github示例here上有效,但现在我不确定如何将命令与我的机器人结合使用。
我要在后台运行的任务是一个函数,该函数使用Google API从文档中获取txt并将其与先前获取的txt文件进行比较以检测更改
originalDoc = fetchDoc.fetch(currentDoc) #fetchDoc - Google API that gets txt
with open('referenceDoc.txt', 'r') as f:
referenceDoc = f.read()
if (len(compare(referenceDoc, originalDoc))) == 0: #compare() is a function I wrote that compares strings
changes = False
print('no changes\n')
else:
changes = True
for x in compare(referenceDoc, originalDoc):
# compares the pulled document with the one stored locally
print(x)
with open('referenceDoc.txt', 'w') as f:
# updates the local file with the current original file
f.write(originalDoc)
请谢谢你们!
答案 0 :(得分:0)
也许这行得通吗?
import asyncio
async def loop():
num=1
while True:
# num+=1
print(num)
await asyncio.sleep(.2)
import string
async def no():
letters=list(string.ascii_letters)
for i in letters:
await asyncio.sleep(.08)
print(i)
functions=asyncio.wait([loop(),no()])
asyncio.run(functions)