My telethon bot was working until I added Quart to my project and to main.py
import asyncio from datetime import datetime from bot.telegram_bot import TelegramBot, client from web.server import create_app from database.database import setup_database import logging logging.basicConfig(level=logging.DEBUG) async def start_telegram_bot(asset_manager): print(f"{datetime.now().strftime('%H:%M:%S.%f')[:-3]} Script was started.") # Start the client await client.start() print("Client started.") # Cache all entities await client.get_dialogs() print("Cached all entities.") bot = TelegramBot() # Log that the script was started and is running start_script_log_text = f"
def create_app(): app = Quart(__name__) app.config["DEBUG"] = True # Enable debug mode ... return app telegram_bot.py
... client = TelegramClient(session_file_path, API_ID, API_HASH) bot = Bot(token=BOT_API_TOKEN) ... but this code gets stuck at await client.start() and gives me the following error:
RuntimeError: Task )() at c:\users\me\appdata\local\programs\python\python39\lib\asyncio\tasks.py:416]> got Future attached to a different loop.
If I instead use this approach it is working:
if __name__ == "__main__": loop = asyncio.get_event_loop() # Get the event loop for the current context try: loop.run_until_complete(main()) # Run the main coroutine finally: loop.close() # Close the loop I read that this approach is soon to be deprecated, and I am using Python 3.9. For this reason I don't want to use this approach.
Источник: https://stackoverflow.com/questions/780 ... uture-pend