Reputation: 714
I dont know how to do multiprocess with bot in telegram with python. I make one thread but if this thread dont finish the bot cant answer messages.
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)
Upvotes: 3
Views: 11502
Reputation: 2375
Try decorating your functions with @run_async:
from telegram.ext.dispatcher import run_async
@run_async
def purga():
now = datetime.now()
Read more about it here:
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.
Upvotes: 4