Advertisement
FanaticExplorer

asyncio_bot+worker

Mar 27th, 2023
641
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. from config import test_token
  2. API_TOKEN = test_token
  3.  
  4. import asyncio
  5. from aiogram import Bot, Dispatcher, types
  6. from aiogram.utils import executor
  7.  
  8. bot = Bot(token=API_TOKEN)
  9. dp = Dispatcher(bot)
  10.  
  11. queue = asyncio.Queue(maxsize=100)
  12.  
  13.  
  14. async def worker():
  15.     while True:
  16.         user_msg, video_status_msg = await queue.get()
  17.         #обрабатываем инфу
  18.         queue.task_done()
  19.  
  20.  
  21. @dp.message_handler(content_types = ['text'])
  22. async def process_message(message: types.Message):
  23.     status_msg = await message.answer('Вы добавлены в очередь!')
  24.     await queue.put([message, status_msg])
  25.    
  26.  
  27. if __name__ == '__main__':
  28.     asyncio.gather(worker(), executor.start_polling(dp, skip_updates=True))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement