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

Asyncslot eager execution and qtinter.modal #18

Open
stat1c-void opened this issue Aug 9, 2023 · 0 comments
Open

Asyncslot eager execution and qtinter.modal #18

stat1c-void opened this issue Aug 9, 2023 · 0 comments

Comments

@stat1c-void
Copy link

stat1c-void commented Aug 9, 2023

Hi!
Firstly, thanks for the awesome library!

I've noticed that asyncslot and modal might not work correctly all the time. Particularly, when modal is used in the eagerly executed part of an asyncslot.

Environment: Python 3.10.12 (Linux), PySide6 6.5.1.1, qtinter 0.11.0.
I use qtinter.using_asyncio_from_qt().

For example:

# slot is connected via asyncslot
async def on_settings_btn_clicked(self):
    dialog_coro = qtinter.modal(settings_dialog.exec)
    # this call will result in an exception
    result = await dialog_coro()

The exception:

Traceback (most recent call last):
  File "...", line 233, in on_settings_btn_clicked
    result = await dialog_coro()
  File ".../site-packages/qtinter/_modal.py", line 29, in modal_wrapper
    loop.exec_modal(modal_fn)
  File ".../site-packages/qtinter/_base_events.py", line 232, in exec_modal
    raise RuntimeError('QiBaseEventLoop.exec_modal() must be called '
RuntimeError: QiBaseEventLoop.exec_modal() must be called from a coroutine or callback

If I add await asyncio.sleep(0) just before the await of a modal, then everything works fine. Like that:

# slot is connected via asyncslot
async def on_settings_btn_clicked(self):
    dialog_coro = qtinter.modal(settings_dialog.exec)
    await asyncio.sleep(0)
    result = await dialog_coro()

Am I doing something wrong here? What is the best practice for something like this?

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