Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

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

call asyncio.sleep(0.1) RuntimeError: no running event loop #123

Open
wood-j opened this issue May 27, 2020 · 0 comments
Open

call asyncio.sleep(0.1) RuntimeError: no running event loop #123

wood-j opened this issue May 27, 2020 · 0 comments

Comments

@wood-j
Copy link

wood-j commented May 27, 2020

Hello, I have been using quamash with pyqt5 for 2 years, it works great(thanks alot to you).
But recently my envirioment updated, I got error when calling asyncio.sleep(0.1) in pyqt views bisiness.

My environment:

  • linux system with kernel 4.19
  • python3.8
  • Quamash ==0.6.1

Here is some test code could raise the same error as my business:

import sys
import asyncio
import quamash
from PyQt5 import QtWidgets


async def loop_func():
    for i in range(1000):
        print('hello')
        await asyncio.sleep(0.1)


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    loop = quamash.QEventLoop(app)
    asyncio.set_event_loop(loop)
    with loop:
        asyncio.ensure_future(loop_func(), loop=loop)
        loop.run_forever()

Output:

Task exception was never retrieved
future: <Task finished name='Task-1' coro=<loop_func() done, defined at /home/wood/project/data-manage-client/test.py:7> exception=RuntimeError('no running event loop')>
Traceback (most recent call last):
  File "/home/wood/project/data-manage-client/test.py", line 10, in loop_func
    await asyncio.sleep(0.1)
  File "/usr/lib64/python3.8/asyncio/tasks.py", line 637, in sleep
    loop = events.get_running_loop()
RuntimeError: no running event loop

I have search the same error:
https://github.com/gmarull/asyncqt/issues/12
gmarull/asyncqt#13

Refer to that, I solve it with:

    asyncio.set_event_loop(loop)
    asyncio.events._set_running_loop(loop)    # <--------------------------------------------
    with loop:
        ....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant