def main(): bot = Bot(BOT_TOKEN) dp = Dispatcher(bot, None, 0) set_handlers(dp) update_queue = Queue() httpd = WebhookServer(('127.0.0.1', WEBHOOK_PORT), WebhookHandler, update_queue, WEBHOOK_URI, bot) while True: try: httpd.handle_request() if not update_queue.empty(): update = update_queue.get() dp.process_update(update) except KeyboardInterrupt: exit(0)