如何解决如何停止另一个功能?
TOKEN = 'token'
bot = telebot.TeleBot(TOKEN)
def main():
for i in range(0,100):
print(i)
@bot.message_handler(commands=['start'])
def start(message):
main()
@bot.message_handler(commands=['stop'])
def stopfunc(message):
#how to stop the function main() ?
while True:
bot.polling()
解决方法
添加停止标志:
- 向主功能添加逻辑:当停止标志为True时,主功能应返回
- 在stopfunc中将stop标志设置为True
stop = False
def main():
global stop
for i in range(0,100):
if stop:
break
print(i)
@bot.message_handler(commands=['stop'])
def stopfunc(message):
global stop
stop = True
...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。