Telethon: NewMessage event callback taking too long to be triggered on big channels
I have an app that uses Telethon to listen to messages from some big channels (2k+ subscribers) and relay them. Since version 0.17 I’ve been noticing some delays in it. So I made the code below to test if the delay was on Telethon and discovered that telethon has been taking over 20s average to run the callback function.
client = TelegramClient('session', api_id, api_hash, update_workers=1, spawn_read_thread=False).start(phone)
try:
client.get_me()
except RuntimeError:
print('Couldn\'t login to Telegram. Exiting...')
sys.exit(0)
channel= client.get_input_entity('A BIG CHANNEL')
@client.on(events.NewMessage(chats=channel, incoming=True))
def callback(event):
print('Message at {} UTC'.format(event.message.date))
print('Delay was {}s\n'.format((datetime.utcnow() - event.message.date).seconds))
print('Listening for messages...')
client.idle()
OUT:
Message at 2018-02-28 03:50:33 UTC
Delay was 52s
Message at 2018-02-28 03:54:23 UTC
Delay was 26s
When listening from a test channel with just me as a subscriber, there is no delay. I’ve been thinking about rolling back my Telethon version, but maybe you guys can help me with it.
UPDATE:
I rolled back the version of the library to 0.16.2 and the issue still persists. I guess it has something to do with the Telegram API itself. Anyway, can anyone help me with this, regardless?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 7
- Comments: 18 (6 by maintainers)
Links to this issue
Commits related to this issue
- Fix bug with "read" messages. But it's not work in channels with many subscribers. See more https://github.com/LonamiWebs/Telethon/issues/652 — committed to Rudzyansky/WTAntispam by Rudzyansky 3 years ago
I am also facing same issue but less delay like 1 or 2 or 3 or 5 seconds, But i need to get 0 sec delay means it should arrive when it sent, Is that delay problem solved? please provide some information or code regarding to that, so that will very helpful for those who are facing this issue.
Hi, guys! I’m facing the exact same issue. The NewMessage event is taking too long, anyone haves a solution?
I have the same issue. Anyone can confirm that Pyrogram is better with delays than Telethon?
There’s a
timeout
somewhere returned by the API which indicates how often one should callgetDifference
. I guess you can manually “watch” channels you’re interested in with it, but I’ve never tried this because I’ve never seen any delays, so while I think it works I’m not sure. Do not ask how to use it here, we have a group for that and StackOverflow.