@ArtikSK

Как сделать, что бы две функции работали одновременно python pyrogram?

Есть две функции flud_to_phantom, flud. Надо что бы они работали одновременно никак не получается настроить из-за самой асинхронной работы клиентов
async def flud_to_phantom(new_...):
    if is_phantom:
        global sessions
        while True:
            app = Client(name=account)
            text = choice(messages)
            async def ph_flud():
                async with app:
                    await app.send_message(chat_id=new_chats[chat_n].id, text=text)
                    await app.stop()

            app.run (ph_flud())
            await asyncio.sleep(phantom_delay)


async def flud(accou...):
    for account in account_list:
        try:
            app = Client(name=account)
            async def connect_to_main():
                async with app:
                    await app.join_chat(chat_id=chat_link)
                    await app.stop()
           app.run(await connect_to_main())

        except UserAlreadyParticipant:
            print('акаунт уже в группе')
        print('Успешно')

    while True:
        app_flud = Client(name=account)
        text = choice(messages)
        async def in_flud():
            async with app_flud:
                await app_flud.send_message(chat_id=chat.id, text=text)
                await app_flud.stop()
        app_flud.run(await in_flud())
        acc_n = counter(acc_n, account_list)
        await asyncio.sleep(delay)

Помогите настроить, а то я уже 5 час пробую
последнее что пытался это вызвать вот так(Подскажите что не так делаю, я пересмотрел уже 5 видосов, прочитал документацию но ничего не могу найти):
async def runner(new_ch...):
    task_1 = asyncio.create_task(flud(accoun...))
    task_2 = asyncio.create_task(flud_to_phantom(new_...))
    await asyncio.gather(task_1, task_2)

Практически при всех попытках одна ошибка:
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Traceback (most recent call last):
  File "C:\Users\....\main.py", line 275, in <module>
    main()
  File "C:\Users\....\main.py", line 263, in main
    loop.run_until_complete(runner(new_ch...,
  File "C:\Users\...\Python\Python310\lib\asyncio\base_events.py", line 646, in run_until_complete
    return future.result()
  File "C:\Users\...\main.py", line 216, in runner
    await asyncio.gather(task_1, task_2)
  File "C:\Users\...\main.py", line 98, in flud
    asyncio.create_task(app.run(await connect_to_main()))
  File "C:\Users\..venv\lib\site-packages\pyrogram\methods\utilities\run.py", line 85, in run
    run(idle())
  File "C:\Users\..Python\Python310\lib\asyncio\base_events.py", line 622, in run_until_complete
    self._check_running()
  File "C:\Use...\Python310\lib\asyncio\base_events.py", line 582, in _check_running
    raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running
sys:1: RuntimeWarning: coroutine 'idle' was never awaited

Process finished with exit code 1
  • Вопрос задан
  • 255 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы