【发布时间】:2021-04-11 22:10:08
【问题描述】:
我需要每 60 秒为我的所有汽车举办一次活动。我对下面代码的问题是while循环直到超时(60)才结束,因此只有汽车中的第一辆车在运行。
class RunCars(BaseEvent):
def __init__(self):
interval_seconds = 60 # Set the interval for this event
super().__init__(interval_seconds)
# run() method will be called once every {interval_seconds} minutes
async def run(self, client, cars):
for car in cars:
channel = get_channel(client, "general")
await client.send_message(channel, 'Running this '+str(car))
await msg.add_reaction(str(get_emoji(':smiley:')))
reaction = None
while True:
if str(reaction) == str(get_emoji(':smiley:'))
await client.send_message(channel, 'Finished with this '+str(car))
try:
reaction, user = await client.wait_for('reaction_add', timeout=60, check=check)
except:
break
我尝试将代码更改为多线程进程,但在函数内部的 async/await 和 pickle 函数本身存在问题。
如果您有任何关于如何解决此问题的建议,我将不胜感激。
【问题讨论】:
标签: python python-3.x async-await python-asyncio python-multiprocessing