Телеграм-бот не останавливается
Проблема следующая, после нажатия Ctrl+C, в терминале выводится следующее сообщение
INFO:aiogram.dispatcher.dispatcher:Stop polling...
WARNING:aiogram:Goodbye!
И дальнейшая работа с терминалом не является возможной, поскольку на этом сообщении он и зависает
Код который запускает бота
#bot.py
import asyncio
import datetime
import Scheduler
from aiogram import executor
from dispatcher import dp
from db import BotDB
import handlers
db = BotDB("Help_For_Tutors.db")
async def send_scheduled_message_lesson():
while True:
await db.connect()
await Scheduler.send_message_lesson()
await asyncio.sleep(60)
async def send_scheduled_message_lesson_status():
while True:
await db.connect()
await Scheduler.send_message_lesson_status()
await asyncio.sleep(30*60)
async def duplication():
while True:
await db.connect()
await Scheduler.make_duplicates()
await asyncio.sleep(30*60)
async def send_scheduled_subscription_reminders():
while True:
await db.connect()
await Scheduler.send_subscription_reminders()
await asyncio.sleep(86400)
async def add_class():
today = datetime.datetime.now()
today_str = today.strftime("%m-%d")
while True:
await db.connect()
if today_str == "08-30":
await Scheduler.update_class()
await asyncio.sleep(86400)
else:
await asyncio.sleep(86400)
async def on_startup(dp):
asyncio.create_task(send_scheduled_message_lesson())
asyncio.create_task(send_scheduled_message_lesson_status())
asyncio.create_task(duplication())
asyncio.create_task(add_class())
# asyncio.create_task(send_scheduled_subscription_reminders())
if __name__ == '__main__':
executor.start_polling(dp, on_startup=on_startup, skip_updates=True)
#dispatcher.py
import logging
from aiogram import Bot, Dispatcher
import config
from aiogram.contrib.fsm_storage.memory import MemoryStorage
# Configure logging
logging.basicConfig(level=logging.INFO)
# prerequisites
if not config.BOT_TOKEN:
exit("No token provided")
# init
storage = MemoryStorage()
bot = Bot(token=config.BOT_TOKEN, parse_mode="HTML")
dp = Dispatcher(bot, storage=storage)
Конструкцию подобного плана не предлагайте
if __name__ == '__main__':
try:
executor.start_polling(dp, on_startup=on_startup, skip_updates=True)
except KeyboardInterrupt:
print("Bot has been interrupted. Exiting...")
Я уже пробовал ее, она не помогает
Ответы (1 шт):
Автор решения: Глеб
→ Ссылка
Комбинация клавиш Ctrl-C в терминале обрывает выполнение программы. Чтобы вставить что-нибудь, вам придется пользоваться правой кнопкой мыши.