E
E
enabl32018-02-08 15:56:05
Python
enabl3, 2018-02-08 15:56:05

How to organize multi-threaded requests for command execution in using Telegram bot?

Hello.
When the bot is used by different people at the same time, it works in turn.
From the beginning it processes the request of one, after the second.
If these are simple commands, then this is not noticeable, but there are commands in which scripts are written for execution, and until this script works, it does not take another command.
Python bot.
Found this but not sure if it's correct.

import threading
theVar = 1
class MyThread(threading.Thread):
    def run ( self ):
        global theVar
def listener(messages):
    @bot.message_handler(commands=['script1'])
    def handle_script1_request(message):
        ip = message.text.split()[-1]
            result = ssh.get_script1(ip)
            bot.send_message(message.chat.id, result)
        theVar = theVar + 1
for x in xrange ( 20 ):
    MyThread().start()

How to tailor the code to all the queries I have so that they can be used by a different number of people at the same time.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
n293, 2018-02-08
@n293

python-telegram-bot has a decorator like @run_async
Yes, it can solve the problem: https://github.com/python-telegram-bot/python-tele...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question