You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't know whether it is a "bug"( I have upgrade) . If I shouldn't have posted this question in this section, I apologize. Please let me know where it would be more appropriate. This issue seems to be related to a conflict.
To avoid blocking the normal operation of the UI, I start a thread when the user clicks a button. The thread uses asyncio event loop execute an asynchronous entry program.
The following code is a simplified version of the implementation of this process.
File part 0 missing (caused by UploadProfilePhotoRequest)
Sleeping for 4s (0:00:04) on UpdateProfilePhotoRequest flood wait
Expected behavior
no exceptions .
Actual behavior
File part 0 missing (caused by UploadProfilePhotoRequest)
Sleeping for 4s (0:00:04) on UpdateProfilePhotoRequest flood wait
Traceback
I debug this problem for days .
I add log in telethon's UserMethodscall and found there mightbe a conflict .
the log code added in telethon/client/users.py:
classUserMethods:
asyncdef__call__(self: 'TelegramClient', request, ordered=False, flood_sleep_threshold=None):
returnawaitself._call(self._sender, request, ordered=ordered)
asyncdef_call(self: 'TelegramClient', sender, request, ordered=False, flood_sleep_threshold=None):
# print(f"self: {id(self)} equl:{id(asyncio.get_running_loop()) == id(self._loop)} running_loop: {id(asyncio.get_running_loop())} , self._loop: {id(self._loop)} request: {type(request)}`{id(request)}` sender: {type(sender)}`{id(sender)}`")print(f"self: {id(self)} request: {type(request)}`{id(request)}` sender: {type(sender)}`{id(sender)}`")
ifself._loopisnotNoneandself._loop!=helpers.get_running_loop():
raiseRuntimeError('The asyncio event loop must not change after connection (see the FAQ for details)')
# if the loop is None it will fail with a connection error later onifflood_sleep_thresholdisNone:
flood_sleep_threshold=self.flood_sleep_thresholdrequests= (requestifutils.is_list_like(request) else (request,))
forrinrequests:
ifnotisinstance(r, TLRequest):
raise_NOT_A_REQUEST()
awaitr.resolve(self, utils)
# ...............# ...............
I print the self(client) 's id, self._loop id (never changed) , runningloop is equl self._loop ( they are always the same ) request type and id , sender's id .
the confilct log is here :
the task count is 2 .
the get_me/ upload 's request log is right .
the uploadprofilerequest's log is confilct . the second task's instance changed to the first task's instance and caused error TypeInputPhoto and flood rpc error .
I read the FAQ and Compatibility and Convenience document .
I understand that the esteemed author has advised everyone to avoid using threads whenever possible. However, it seems that in GUI programs, the only way to prevent blocking is to start a thread. Therefore, I would still appreciate any suggestions regarding this issue. Thank you.
Btw: In fact , my oldest code was run each client in thread's eventloop (multithread which have one loop each) . it caused " RunningTimeError(The asyncio event loop must not change after connection (see the FAQ for details)) " , but the code works well in console application too ....
Telethon version
1.38.1
Python version
3.12.7
Operating system (including distribution name and version)
Code that causes the issue
I don't know whether it is a "bug"( I have upgrade) . If I shouldn't have posted this question in this section, I apologize. Please let me know where it would be more appropriate. This issue seems to be related to a conflict.
To avoid blocking the normal operation of the UI, I start a thread when the user clicks a button. The thread uses asyncio event loop execute an asynchronous entry program.
The following code is a simplified version of the implementation of this process.
WinMain
feature
these code works well in console multithread . But failed in PyQT thread .
Exception detail .
Expected behavior
no exceptions .
Actual behavior
Traceback
I debug this problem for days .
I add log in telethon's
UserMethods
call and found there mightbe a conflict .the log code added in
telethon/client/users.py
:I print the self(client) 's id, self._loop id (never changed) , runningloop is equl self._loop ( they are always the same ) request type and id , sender's id .
the confilct log is here :
I read the FAQ and Compatibility and Convenience document .
I understand that the esteemed author has advised everyone to avoid using threads whenever possible. However, it seems that in GUI programs, the only way to prevent blocking is to start a thread. Therefore, I would still appreciate any suggestions regarding this issue. Thank you.
Btw: In fact , my oldest code was run each client in thread's eventloop (multithread which have one loop each) . it caused " RunningTimeError(The asyncio event loop must not change after connection (see the FAQ for details)) " , but the code works well in console application too ....
Telethon version
1.38.1
Python version
3.12.7
Operating system (including distribution name and version)
Windows 11
Other details
PyQt5==5.15.11
PyQt5-Qt5==5.15.2
PyQt5_sip==12.15.0
Checklist
pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip
and triggered the bug in the latest version.The text was updated successfully, but these errors were encountered: