TelegramPlayGround / pyrogram

PyroGramFORK | Telegram MTProto API framework in Python for users and bots | PyroGramFORK
https://telegramplayground.github.io/pyrogram/
GNU Lesser General Public License v3.0
83 stars 14 forks source link

No updates / freeeze #101

Open Cosangeles55 opened 4 days ago

Cosangeles55 commented 4 days ago

Checklist

Description

A serious issue: accounts with many chat subscriptions are not receiving updates. @self.client.on_message() @self.client.on_edited_message() Moreover, they operate very, very slowly. It worked fine when I ran it overnight, but after a server restart six hours later, there were zero updates again. It might depend on the message activity in the chats—if there are too many updates, the accounts seem to hang. This issue does not occur in Kurigram...

Steps to reproduce

Change to Kurigram, change to pyrotgfork

Code example

@self.client.on_message()
        @self.client.on_edited_message()
        # @self.client.on_message_reaction()
        async def on_message(client, *args):
            try:
                self.event_queue.put_nowait({
                    'type': 'on_message',
                    'value': args
                })
            except Exception as e:
                print(e)

        @self.client.on_deleted_messages()
        async def on_deleted_messages(client, *args):
            try:
                self.event_queue.put_nowait({
                    'type': 'on_deleted_messages',
                    'value': args
                })
            except Exception as e:
                print(e)

        @self.client.on_raw_update()
        @self.client.on_inline_query()
        @self.client.on_chat_member_updated()
        @self.client.on_callback_query()
        @self.client.on_poll()
        @self.client.on_user_status()
        @self.client.on_chat_join_request()
        async def on_raw_update(client, *args):
            try:
                self.event_queue.put_nowait({
                    'type': 'on_raw_update',
                    'value': args
                })
            except Exception as e:
                print(e)

        @self.client.on_disconnect()
        async def on_disconnect(client, *args):
            self.is_connected = self.client.is_connected

Logs

No response

Cosangeles55 commented 2 days ago

backend_fastapi | [2024-10-20 13:32:38,932.932] ERROR - asyncio - Task exception was never retrieved backend_fastapi | future: <Task finished name='Task-1088' coro=<LeadsMonitoringMessages.run() done, defined at /backend/fast_api_leads/monitoring/mesages.py:50> exception=RuntimeError("Task <Task pending name='Task-1091' coro=<Start.start() running at /usr/local/lib/python3.10/site-packages/pyrogram/methods/utilities/start.py:58> cb=[_chain_future.._call_set_state() at /usr/local/lib/python3.10/asyncio/futures.py:392]> got Future <Future pending cb=[_chain_future.._call_check_cancel() at /usr/local/lib/python3.10/asyncio/futures.py:385]> attached to a different loop")> backend_fastapi | Traceback (most recent call last): backend_fastapi | File "/backend/fast_api_leads/monitoring/mesages.py", line 51, in run backend_fastapi | await self.init() backend_fastapi | File "/backend/fast_api_leads/monitoring/mesages.py", line 58, in init backend_fastapi | self.app = await self.telegram_api.getAppByToken(self.token.token) backend_fastapi | File "/backend/telegram/app.py", line 435, in getAppByToken backend_fastapi | await asyncio.wait_for(app.start(), timeout=15) backend_fastapi | File "/usr/local/lib/python3.10/asyncio/tasks.py", line 445, in wait_for backend_fastapi | return fut.result() backend_fastapi | File "/usr/local/lib/python3.10/site-packages/pyrogram/sync.py", line 74, in coro_wrapper backend_fastapi | return await asyncio.wrap_future(asyncio.run_coroutine_threadsafe(coroutine, main_loop)) backend_fastapi | File "/usr/local/lib/python3.10/site-packages/pyrogram/methods/utilities/start.py", line 58, in start backend_fastapi | is_authorized = await self.connect() backend_fastapi | File "/usr/local/lib/python3.10/site-packages/pyrogram/methods/auth/connect.py", line 40, in connect backend_fastapi | await self.load_session() backend_fastapi | File "/usr/local/lib/python3.10/site-packages/pyrogram/client.py", line 803, in load_session backend_fastapi | await self.storage.open() backend_fastapi | File "/usr/local/lib/python3.10/site-packages/pyrogram/storage/memory_storage.py", line 41, in open backend_fastapi | self.conn = await self.loop.run_in_executor(self.executor, sqlite3.connect, ":memory:") backend_fastapi | RuntimeError: Task <Task pending name='Task-1091' coro=<Start.start() running at /usr/local/lib/python3.10/site-packages/pyrogram/methods/utilities/start.py:58> cb=[_chain_future.._call_set_state() at /usr/local/lib/python3.10/asyncio/futures.py:392]> got Future <Future pending cb=[_chain_future.._call_check_cancel() at /usr/local/lib/python3.10/asyncio/futures.py:385]> attached to a different loop

Cosangeles55 commented 2 days ago
        loop = asyncio.get_running_loop()
        monitoring_thread = LeadsMonitoringMessages(
            telegram_api=self.telegram_api,
            producer=self.producer,
            token=token,
            leads_metrics=self.leads_metrics,
            loop=loop
        )
        monitoring_thread.start()
Cosangeles55 commented 2 days ago
def run(self):
    # Запускаем клиент в основном loop
    asyncio.set_event_loop(self.loop)
    asyncio.run_coroutine_threadsafe(self.init(), self.loop)