Telethon: Cannot invoke requests from within update handlers

Hello, i used Telethon 0.11.5 and everything worked, but when i installed new Telethon 0.13 version some part of my code stopped working.

@staticmethod
def update_handler(self, update_object):
    if isinstance(update_object, UpdateShortMessage):
        MyBot.join_channels(update_object)
self.add_update_handler(self.update_handler)
while True:  # listening for updates
    pass

these fucntions were in class made like in offical example. (MyBot is my class)

def join_channels(self, channels):
    print("something")          
    self(ResolveUsernameRequest(channel))
    print("i have done all work")

normally at Telethon 0.11.5 join_channels functions used to print ‘something’ then invoke request and print “i have done…” BUT in Telethon 0.13 it ony prints “something” and after it dont do and print anything. How can i fix it? I have tested and without recieving updates script works fine, maybe there is problem with threads?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 21 (12 by maintainers)

Most upvoted comments

Workaround for v0.13:

updates = []
def on_update(update):
    updates.append(update)

while True:
    if not updates:
        sleep(0.1)
        continue

    # Work with the added updates here. Note that this is not
    # thread-safe but that's left as an exercise to the reader.

Just install v0.12.2, it’s the latest version which doesn’t use this new thread thing. Never ask for a deadline.

How can i install Telethon 0.11.5 back? And how i can send file at 0.11.5 version?

Okay I see the problem. Invoking a request from within the update handler will make it not work. Why? Because it will wait for the ReadThread to receive it, but it’s the ReadThread who reads it and the one who’s waiting, so it hangs.