pyTelegramBotAPItelebot通过/ stop命令从while退出

问题描述

我写了一个机器人,用于通过以下命令检查snmp上的负载均值:snmpwalk -v3 -l authNoPriv -u admin -a SHA -A“ admin”'+服务器+'.1.3.6.1.4.1.2021.10.1.3 .1。

我无法通过stop命令退出while循环。

bot = telebot.TeleBot('xxxxx')

@bot.message_handler(commands=['start'])
def start(message):
    sent = bot.send_message(message.chat.id,'Please input server (example 192.168.0.1)')
    bot.register_next_step_handler(sent,cores)

def cores(message):
    global server
    server = (message.text)
    sent2 = bot.send_message(message.chat.id,'Input number of cores')
    bot.register_next_step_handler(sent2,botstarted)

def botstarted(message):
    global core
    global bye
    core = (message.text)
    cores = float(core)
    bot.send_message(message.chat.id,'Check started,if load average more then number of cores you get Warning message to stop enter /stop')
    while (True):
        b = os.popen('snmpwalk -v3 -l authNoPriv -u admin -a SHA -A "admin" ' + server + ' .1.3.6.1.4.1.2021.10.1.3.1').read()
        d = (b[39:43])
        c = float(b[39:43])
        if c > cores:
            bot.send_message(message.chat.id,'Warning,huge load average: ' + d)
        print(c)
        time.sleep(10)

@bot.message_handler(commands=['stop'])
def stop(message):
    sent3 = bot.send_message(message.chat.id,'bye')
    print(sent3)

bot.polling(none_stop=True)

解决方法

bot.stop_polling()  but this = exit

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...