我不知道如何使用 python 在电报中使用机器人进行多进程。我创建了一个线程,但如果该线程未完成,机器人将无法回复消息。
horaPurga= now.replace(hour=23, minute=36,second=59,microsecond=0)
def purga(threading.Thread):
now = datetime.now()
if now >= horaPurga :
bot.send_message(cid, 'pole')
def run():
while True:
purga.start()
time.sleep(2)
尝试用 @run_async 装饰你的函数:
from telegram.ext.dispatcher import run_async
@run_async
def purga():
now = datetime.now()
在这里阅读更多相关信息:
https://github.com/python-telegram-bot/python-telegram-bot/wiki/Performance-Optimizations https://github.com/python-telegram-bot/python-telegram-bot/wiki/Performance-Optimizations
TLDR:
这实际上并不会让你的代码运行得更快。真正的优势在于网络通信(例如向用户发送消息)或硬盘驱动器上的读/写等 I/O 操作可以同时运行。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)