C
C
CleanyBoom2021-11-21 19:30:30
Python
CleanyBoom, 2021-11-21 19:30:30

1 process shutting down after turning on two other python threading?

import time
from threading import Thread

from telebot import TeleBot, types


bot = TeleBot('')
threads = {}


def some_func(us, text):
    time.sleep(10000)


@bot.message_handler(commands=['start'])
def start_command(message):
    us = message.chat.id
    threads[us] = Thread(target=some_func(us, message.text))
    threads[us].start()
    

def start():
    bot.polling()
    

thr1 = Thread(target=start)


if __name__ == '__main__':
    thr1.start()


I have such code. (The function has been redone, but it is performed for a long time, this is the main point). When you start functions from 2 accounts, the bot itself turns off and stops responding to commands. At 1 everything works fine. This can be solved somehow, or read somewhere about solutions if I could not competently google. Thank you all in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AWEme, 2021-11-21
​​@CleanyBoom

The result of the function call was passed to the target .
To run a function with arguments in a separate thread, you need to pass these same arguments by the args and kwargs keys. https://docs.python.org/3/library/threading.html#t...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question