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

Should qasync.run() be used? #117

Open
pe224 opened this issue Apr 5, 2024 · 0 comments
Open

Should qasync.run() be used? #117

pe224 opened this issue Apr 5, 2024 · 0 comments

Comments

@pe224
Copy link

pe224 commented Apr 5, 2024

In e65c342 the qasync example usage in the README has been updated, along with aiohttp_fetch.py.

Before, it used qasync.run()

async def main():
    app = qasync.QApplication.instance()

    app_close_event = asyncio.Event()
    app.aboutToQuit.connect(app_close_event.set)

    mainWindow = MainWindow()
    mainWindow.show()

    await app_close_event.wait()
    return True


if __name__ == "__main__":
    try:
        qasync.run(main())
    except asyncio.exceptions.CancelledError:
        sys.exit(0)

now it explicitly instantiates/sets the event loop objects and uses run_until_complete()

if __name__ == "__main__":
    app = qasync.QApplication(sys.argv)

    event_loop = qasync.QEventLoop(app)
    asyncio.set_event_loop(event_loop)

    app_close_event = asyncio.Event()
    app.aboutToQuit.connect(app_close_event.set)

    main_window = MainWindow()
    main_window.show()

    with event_loop:
        event_loop.run_until_complete(app_close_event.wait())

What was the reason for the change? Are there differences between the approaches and if yes, which one should be used? (I am using the qasync.run() pattern at the moment)

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