添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account
  • I am sure the error is coming from Pyrogram's code and not elsewhere.
  • I have searched in the issue tracker for similar bug reports, including closed ones.
  • I ran pip3 install -U https://github.com/pyrogram/pyrogram/archive/asyncio-dev.zip and reproduced the issue using the latest development version.
  • Description

    Raise multiple runtime exception while executing await app.stop()

    Steps to Reproduce

    from pyrogram import Client
    import asyncio
    app = Client(
    	'testapp', 250000, 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', bot_token='28xxx:xxxxxx'
    async def main():
    	await app.start()
    	await app.stop()
    if __name__ == "__main__":
    	asyncio.run(main())

    Traceback

    Traceback (most recent call last):
      File "test.py", line 17, in <module>
        asyncio.run(main())
      File "/usr/local/lib/python3.8/asyncio/runners.py", line 43, in run
        return loop.run_until_complete(main)
      File "/usr/local/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
        return future.result()
      File "test.py", line 13, in main
        await app.stop()
      File "/usr/local/lib/python3.8/site-packages/pyrogram/client/client.py", line 885, in stop
        await do_it()
      File "/usr/local/lib/python3.8/site-packages/pyrogram/client/client.py", line 881, in do_it
        await self.terminate()
      File "/usr/local/lib/python3.8/site-packages/pyrogram/client/client.py", line 355, in terminate
        await task
      File "/usr/local/lib/python3.8/site-packages/pyrogram/client/client.py", line 1243, in download_worker
        packet = await self.download_queue.get()
      File "/usr/local/lib/python3.8/asyncio/queues.py", line 163, in get
        await getter
    RuntimeError: Task <Task pending name='Task-64' coro=<Client.download_worker() running at /usr/local/lib/python3.8/site-packages/pyrogram/client/client.py:1243>> got Future <Future pending> attached to a different loop
    ERROR:asyncio:Task exception was never retrieved
    future: <Task finished name='Task-63' coro=<Client.updates_worker() done, defined at /usr/local/lib/python3.8/site-packages/pyrogram/client/client.py:1291> exception=RuntimeError("Task <Task pending name='Task-63' coro=<Client.updates_worker() running at /usr/local/lib/python3.8/site-packages/pyrogram/client/client.py:1293>> got Future <Future pending> attached to a different loop")>
    Traceback (most recent call last):
      File "/usr/local/lib/python3.8/site-packages/pyrogram/client/client.py", line 1293, in updates_worker
        updates = await self.updates_queue.get()
      File "/usr/local/lib/python3.8/asyncio/queues.py", line 163, in get
        await getter
    RuntimeError: Task <Task pending name='Task-63' coro=<Client.updates_worker() running at /usr/local/lib/python3.8/site-packages/pyrogram/client/client.py:1293>> got Future <Future pending> attached to a different loop
    ERROR:asyncio:Task exception was never retrieved
    future: <Task finished name='Task-62' coro=<Client.updates_worker() done, defined at /usr/local/lib/python3.8/site-packages/pyrogram/client/client.py:1291> exception=RuntimeError("Task <Task pending name='Task-62' coro=<Client.updates_worker() running at /usr/local/lib/python3.8/site-packages/pyrogram/client/client.py:1293>> got Future <Future pending> attached to a different loop")>
    Traceback (most recent call last):
      File "/usr/local/lib/python3.8/site-packages/pyrogram/client/client.py", line 1293, in updates_worker
        updates = await self.updates_queue.get()
      File "/usr/local/lib/python3.8/asyncio/queues.py", line 163, in get
        await getter
    RuntimeError: Task <Task pending name='Task-62' coro=<Client.updates_worker() running at /usr/local/lib/python3.8/site-packages/pyrogram/client/client.py:1293>> got Future <Future pending> attached to a different loop
    ERROR:asyncio:Task exception was never retrieved
    future: <Task finished name='Task-61' coro=<Client.updates_worker() done, defined at /usr/local/lib/python3.8/site-packages/pyrogram/client/client.py:1291> exception=RuntimeError("Task <Task pending name='Task-61' coro=<Client.updates_worker() running at /usr/local/lib/python3.8/site-packages/pyrogram/client/client.py:1293>> got Future <Future pending> attached to a different loop")>
    Traceback (most recent call last):
      File "/usr/local/lib/python3.8/site-packages/pyrogram/client/client.py", line 1293, in updates_worker
        updates = await self.updates_queue.get()
      File "/usr/local/lib/python3.8/asyncio/queues.py", line 163, in get
        await getter
    RuntimeError: Task <Task pending name='Task-61' coro=<Client.updates_worker() running at /usr/local/lib/python3.8/site-packages/pyrogram/client/client.py:1293>> got Future <Future pending> attached to a different loop
    ERROR:asyncio:Task exception was never retrieved
    future: <Task finished name='Task-60' coro=<Client.updates_worker() done, defined at /usr/local/lib/python3.8/site-packages/pyrogram/client/client.py:1291> exception=RuntimeError("Task <Task pending name='Task-60' coro=<Client.updates_worker() running at /usr/local/lib/python3.8/site-packages/pyrogram/client/client.py:1293>> got Future <Future pending> attached to a different loop")>
    Traceback (most recent call last):
      File "/usr/local/lib/python3.8/site-packages/pyrogram/client/client.py", line 1293, in updates_worker
        updates = await self.updates_queue.get()
      File "/usr/local/lib/python3.8/asyncio/queues.py", line 163, in get
        await getter
    RuntimeError: Task <Task pending name='Task-60' coro=<Client.updates_worker() running at /usr/local/lib/python3.8/site-packages/pyrogram/client/client.py:1293>> got Future <Future pending> attached to a different loop
    ERROR:asyncio:Task exception was never retrieved
    future: <Task finished name='Task-67' coro=<Client.download_worker() done, defined at /usr/local/lib/python3.8/site-packages/pyrogram/client/client.py:1241> exception=RuntimeError("Task <Task pending name='Task-67' coro=<Client.download_worker() running at /usr/local/lib/python3.8/site-packages/pyrogram/client/client.py:1243>> got Future <Future pending> attached to a different loop")>
    Traceback (most recent call last):
      File "/usr/local/lib/python3.8/site-packages/pyrogram/client/client.py", line 1243, in download_worker
        packet = await self.download_queue.get()
      File "/usr/local/lib/python3.8/asyncio/queues.py", line 163, in get
        await getter
    RuntimeError: Task <Task pending name='Task-67' coro=<Client.download_worker() running at /usr/local/lib/python3.8/site-packages/pyrogram/client/client.py:1243>> got Future <Future pending> attached to a different loop
    ERROR:asyncio:Task exception was never retrieved
    future: <Task finished name='Task-66' coro=<Client.download_worker() done, defined at /usr/local/lib/python3.8/site-packages/pyrogram/client/client.py:1241> exception=RuntimeError("Task <Task pending name='Task-66' coro=<Client.download_worker() running at /usr/local/lib/python3.8/site-packages/pyrogram/client/client.py:1243>> got Future <Future pending> attached to a different loop")>
    Traceback (most recent call last):
      File "/usr/local/lib/python3.8/site-packages/pyrogram/client/client.py", line 1243, in download_worker
        packet = await self.download_queue.get()
      File "/usr/local/lib/python3.8/asyncio/queues.py", line 163, in get
        await getter
    RuntimeError: Task <Task pending name='Task-66' coro=<Client.download_worker() running at /usr/local/lib/python3.8/site-packages/pyrogram/client/client.py:1243>> got Future <Future pending> attached to a different loop
    ERROR:asyncio:Task exception was never retrieved
    future: <Task finished name='Task-65' coro=<Client.download_worker() done, defined at /usr/local/lib/python3.8/site-packages/pyrogram/client/client.py:1241> exception=RuntimeError("Task <Task pending name='Task-65' coro=<Client.download_worker() running at /usr/local/lib/python3.8/site-packages/pyrogram/client/client.py:1243>> got Future <Future pending> attached to a different loop")>
    Traceback (most recent call last):
      File "/usr/local/lib/python3.8/site-packages/pyrogram/client/client.py", line 1243, in download_worker
        packet = await self.download_queue.get()
      File "/usr/local/lib/python3.8/asyncio/queues.py", line 163, in get
        await getter
    RuntimeError: Task <Task pending name='Task-65' coro=<Client.download_worker() running at /usr/local/lib/python3.8/site-packages/pyrogram/client/client.py:1243>> got Future <Future pending> attached to a different loop
      PozitronikTech, MrBotDeveloper, neginkashkooliiis, Tao-kun, pkeorley, and Ready4FUN reacted with thumbs up emoji
      Saadmairaj, greed2411, and NumeroQuadro reacted with rocket emoji
        All reactions
            changed the title
    Stop program cause RuntimeError: Task got Future attached to a different loop (Asyncio)
    Using asyncio.run() raises an error
          Apr 24, 2020
    

    @KunoiSayami Thanks, this is a known issue. asyncio.run() is not working currently, but you can use asyncio.get_event_loop().run_until_complete(main()) or app.run(main()).

    Both will have similar functionality right? i.e it won't hinder anything else or any caveats to this approach?