带电传器的压线机

问题描述

我想在主线程上使用另一个线程。 主要的一个是电报bot api,第二个是opencv文件。 我尝试了所有就绪的多处理和子进程,但是由于该机器人在其上运行的线程库而无法使用。 毕竟我要建立“子线程”,但它不会退出“子线程”。它只能工作一次,仅此而已。 我没有找到任何有用的信息来了解如何使用电报机器人中的 other 命令退出“子线程”, 喜欢:

elif telegramText == '/exit_thread':
        if my_thread.isalive():
           my_thead.exit()/my_thread.end()
           bot.sendMessage(chat_id,str("the thread isnt working,re-enter the /enb command for the new open cv thread"))

将线程创建为数字1:

elif telegramText == '/enb':
        numbers = [1]
        for number in numbers:
            my_thread = Thread(target=doubler,args=(number,))
            my_thread.start()

定义线程需要做什么:

def doubler(number):
if number==1:
    #print(threading.currentThread().getName() + '\n')
    bot.sendMessage(chat_id,str("Its on,Youre safe!"))
    if full_body_detec.body_detec():
        bot.sendMessage(chat_id,str("I saw some-one!! see it your self"))
        bot.sendPhoto(chat_id,photo=open('intruder.jpg','rb'))
        bot.sendVideo(chat_id = chat_id,video = open('output2.mp4',mode ='rb'))

我真的陷入困境,伙计们将感谢您的帮助。

解决方法

使用threading.Thread.join方法my_thread.join(),但不要使用.exit().end()

P.S。注意错别字,我看到您使用了2个变量:my_thead和my_th r ead