Added timeout for every method.

This commit is contained in:
Forden 2019-03-21 02:04:51 +03:00
parent 39c8d859dc
commit a8366125f1
6 changed files with 375 additions and 199 deletions

View file

@ -0,0 +1,21 @@
import asyncio
import logging
from aiogram import Bot, types, filters
from aiogram.dispatcher import Dispatcher
from aiogram.utils.executor import start_polling
API_TOKEN = 'BOT TOKEN HERE'
logging.basicConfig(level=logging.INFO)
loop = asyncio.get_event_loop()
bot = Bot(token=API_TOKEN, loop=loop, connection_timeout=5)
dp = Dispatcher(bot)
@dp.message_handler(filters.CommandStart())
async def start(message: types.Message):
await message.reply_photo(types.InputFile('data/cat.jpg'), f'Cat with Bot\'s timeout: {bot.connection_timeout.total}!')
await bot.send_photo(message.chat.id, types.InputFile('data/cats.jpg'), 'More cats with timeout 1 second!', timeout=1)
if __name__ == '__main__':
start_polling(dp, loop=loop, skip_updates=True)