Как продолжить цикл списка, не дожидаясь новых сообщений, телемарафон PythonPython

Программы на Python
Ответить Пред. темаСлед. тема
Гость
 Как продолжить цикл списка, не дожидаясь новых сообщений, телемарафон Python

Сообщение Гость »


I'm new with telethon and I have a telethon python script that is listening for telegram messages, all this part works correctly, but I'm improving my script, what I need to achieve is the following:

I'm looping a list, that needs to do something that takes around 10-15 seconds for each item in the list, If I do this right after the message arrives, I lost those 10-15 seconds, hence I decided to change my code but I'm facing an issue that next item is not iterated as telethon is waiting now for the next message to arrive hence the code starts failing, I'm new with async functions and probably is something easy but I can't get it, please see my code example below:

Working code:

client = TelegramClient('session', API_ID, API_HASH) @client.on(events.NewMessage(chats=chatId)) async def my_event_handler(event): text = event.raw_text for item in items: # do something, it works fine, but I need to have other stuff ready # before telegram message arrives client.start() client.run_until_disconnected() Looking for something like this?

for item in items: # do something before a new message arrives client = TelegramClient('session', API_ID, API_HASH) @client.on(events.NewMessage(chats=chatId)) async def my_event_handler(event): text = event.raw_text # do all the stuff that I need to do right after message is arrived await client.disconnect() client.start() client.run_until_disconnected() The issue with code above is that once client is disconnected it finishes the code, but I'm looking to continue with the next iteration


Источник: https://stackoverflow.com/questions/780 ... hon-python
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»