А есть мысли, почему вот такой код
async def main(api_id, api_hash, tg_session, chat_id, db_session):
async with TelegramClient(StringSession(tg_session), api_id, api_hash) as client:
await client.start()
chan = await client.get_entity(int(chat_id))
events = await client.get_admin_log(chan)
print("start for loop")
for event in events:
print(event.user_id)
await asyncio.sleep(5)
print(f"{event.user_id} awaited")
continue
asyncio.run(main(api_id, api_hash, tg_session, parsing_chat_id, Session))
даёт вот такой вывод?
start for loop
6550133864
6550133864 awaited
5171756347
5171756347 awaited
2002370110
2002370110 awaited
1682226622
Для сравнения, нормальный пример нормального кода
async def bar(item: int) -> int:
print("Started")
await asyncio.sleep(5)
print("Finished")
return item ** 2
async def foo():
items = range(1, 10)
tasks = [bar(item) for item in items]
new_items = await asyncio.gather(*tasks)
return new_items
if __name__ == '__main__':
results = asyncio.run(foo())
print(results)
выводит нормальный вывод:
Started
...
Started
Finished
...
Finished
[1, 4, 9, 16, 25, 36, 49, 64, 81]