python - 带 Telepot 的 Klling 线程
问题描述
我想在我的主线程上使用另一个线程。主要的一个是电报机器人api,第二个是opencv文件。我尝试了所有就绪的多处理和子进程,但由于机器人运行的线程库,它无法工作。毕竟我设法建立了“子线程”,但它不会退出“子线程”。它只工作一次,就是这样。我没有找到有关如何使用电报机器人的其他命令退出“子线程”的任何有用信息,例如:
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()
PS 注意拼写错误,我看到您使用的 2 个变量:my_thead 和my_th读取
推荐阅读
- javascript - 如何从 Google 控制台订阅中获取价格并在 android 文本视图中显示
- javascript - WebAssembly 中的浏览器安全问题
- javascript - NodeJS Express Async 不处理更多请求
- android - 无法将值附加到数据类中
- javascript - 获取未定义的值。Javascript / React / 映射
- javascript - Vue推入嵌套数组
- mysql - 优化 mysql 中具有连接和联合的查询
- python - 如何在不使用矩阵运算的情况下编写迭代梯度下降?
- scala - Spark写入两次插入某些记录
- python - 如何使用 RGB 图像上的调色板提取主色?