PythonAnywhere上Telegram Bot无法停止的问题求助
问题描述
在PythonAnywhere上部署了一个简单的Telegram Bot,包含两个消息处理器:一个是echo功能,另一个用于响应命令,测试运行正常。但尝试停止Bot时,在任务区终止对应任务后,显示无运行中任务,但Bot仍在运行。已删除Bot文件并禁用web服务,请问如何停止这个Bot?
部署的代码
from flask_sslify import SSLify from flask import Flask from aiogram import Bot, types, executor, Dispatcher PROXY_URL = "http://proxy.server:3128" app = Flask(__name__) sslify = SSLify(app) bot1= Bot(token='token', proxy=PROXY_URL) dp1=Dispatcher(bot1) def on_startup1(): print("Бот 1 вышел в онлайн") @dp1.message_handler(commands=['Подивитись']) async def check_info_from_database(message: types.message): await bot1.send_message(user_id, "Some text") @dp1.message_handler() async def echo(message: types.message): await message.answer(message.text) executor.start_polling(dp1, skip_updates=True, on_startup=on_startup1())
解决步骤
- 打开PythonAnywhere的控制台,进入部署Bot时使用的虚拟环境(如有配置)。
- 执行命令
ps aux | grep python,列出所有Python进程,找到与你的Bot相关的进程行,记录对应的进程ID(PID)。 - 执行
kill -9 <PID>(将<PID>替换为实际的进程ID),强制终止该进程。若存在多个相关Bot进程,重复此步骤逐个清除。 - 再次执行
ps aux | grep python,确认目标进程已消失,Bot即可停止运行。
内容的提问来源于stack exchange,提问作者Ярослав Кузьмін
相关产品推荐
相关产品推荐

