如何使用telegram bot python同时工作

2024-10-02 12:31:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我不知道如何用python在多进程中使用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)

Tags: 消息进程def机器人线程threadnowreplace
1条回答
网友
1楼 · 发布于 2024-10-02 12:31:06

尝试用@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

TLDR:

this does not actually make your code run faster. The real advantage is that I/O operations like network communication (eg. sending a message to a user) or reading/writing on your hard drive can run concurrently.

相关问题 更多 >

    热门问题