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?
Use three ``` to format code blocks, otherwise it'll be completely unreadable.
But... i have used

No, you had put a single backtick, `. Anyway.
To begin with, you're mixing @staticmethod with a first self attribute, which is probably not what you want.
Second, you have a busy loop (while True: pass) which is killer for the CPU. Add some sleep().
after it dont do and print anything
Some stack trace would be helpful.
well, my mistake, i don't actually use self in staticmethod. And i hav eadded time.sleep(0.1) But script still doesnt work
I have not trace! script work but... just dont print anything after invoking a method
But... i have used
Now the image loaded. I edited your comment, it says up there. Anyway. Have you tried anything to troubleshoot the issue? Like killing the thread to see where it stops or similar.
Sorry but i realy am not familiar with threads. how can i check it? I just tried to run script without updates at all and give channels parametre in func join_channels directly(it works so)
how can i check it?
Pressing Ctrl+C to stop everything should work and tell you were it stopped. Press it twice at least.
I tried to debug and i script stops before invoking method, and just dont do anything
self(ResolveUsernameRequest(channel))
What's the type of channel?
string
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.
How can i install Telethon 0.11.5 back?
And how i can send file at 0.11.5 version?
so how i can awoid this problem in 0.13?
How can i install Telethon 0.11.5 back?
You look on the internet for an answer, "how to install a previous version pip". Also, go with v0.12.2, no need to go back as far as v0.11.5.
And how i can send file at 0.11.5 version?
You RTFM.
so how i can awoid this problem?
You wait until I fix it, or you fix it and submit a pull request, or you downgrade.
when are you going to fix this? I have a deadline soon:(
Just install v0.12.2, it's the latest version which doesn't use this new thread thing. Never ask for a deadline.
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.
OK, thanks a lot. My best wishes. I think i should give you a star now:)
Thanks for the star. I'm still thinking how to design this in the most appropriated way.
Whoops why did you close this? I need to figure out how to call things from the updates thread.
You're still advised to use a separate thread for this, because it will prevent everything else from being read while you're invoking said request.