question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Loop stops after dialog goes away

See original GitHub issue

Please disregard if I’m doing something bone-headed. It may be due to my lack, of either asyncio or Qt knowledge.

I’m trying to show two dialogs, one after the other. In this small example I use QWizard’s After the first one goes away either by pressing cancel or finish, I get the error shown below. However, if I have a button sitting there in the background it behaves just fine. If instead of running run_until_complete(amain()) I run asyncio.ensure_future(amain()) followed by loop.run_forever() then I don’t get any errors but the 2nd wizard never shows up. It just exists as soon as there is nothing left to display on the screen.

#!/usr/bin/env python3
import asyncio
import sys

from PyQt5.QtWidgets import QApplication, QWizard, QWizardPage, QDialog, QPushButton
from quamash import QEventLoop


def async_dialog_exec(dlg: QDialog):
    fut = asyncio.Future()
    dlg.finished.connect(lambda result: fut.set_result(result))
    dlg.open()
    return fut

async def amain():
    # if these two lines are uncommented you'll be able to see both wizards
    # b = QPushButton('hi')
    # b.show()
    wiz1 = QWizard()
    wiz1.addPage(QWizardPage())
    wiz1.setWindowTitle("First Wizard")
    result = await async_dialog_exec(wiz1)
    if result != QDialog.Accepted:
        return

    wiz2 = QWizard()
    wiz2.addPage(QWizardPage())
    wiz2.setWindowTitle("Second Wizard")
    result = await async_dialog_exec(wiz2)
    if result != QDialog.Accepted:
        return

app = QApplication(sys.argv)
loop = QEventLoop(app)
asyncio.set_event_loop(loop)
with loop:
    loop.run_until_complete(amain())
Traceback (most recent call last):
  File "/home/vagrant/PycharmProjects/test/dlg_example.py", line 37, in <module>
    loop.run_until_complete(amain())
  File "/opt/Python-3/lib/python3.5/site-packages/quamash/__init__.py", line 270, in run_until_complete
    raise RuntimeError('Event loop stopped before Future completed.')
RuntimeError: Event loop stopped before Future completed.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
harvimtcommented, Jul 20, 2016

adding app.setQuitOnLastWindowClosed(False) makes everything work correctly.

0reactions
harvimtcommented, Jul 20, 2016

replicated on windows. In all cases the problem is that the loop exits when all windows are closed, so a dummy window that keeps the app open and the

do to the magic of duck typing, this will work:

app = QApplication(sys.argv)
wiz1 = QWizard()
wiz1.addPage(QWizardPage(wiz1))
wiz1.setWindowTitle("First Wizard")
loop = QEventLoop(wiz1)
asyncio.set_event_loop(loop)
with loop:
    loop.run_forever()

wiz2 = QWizard()
wiz2.addPage(QWizardPage(wiz2))
wiz2.setWindowTitle("Second Wizard")
loop = QEventLoop(wiz2)
asyncio.set_event_loop(loop)
with loop:
    loop.run_forever()
Read more comments on GitHub >

github_iconTop Results From Across the Web

Break out of loop/continue next from AlertDialog OnClick
I tried Haresh Chhelana suggestion but the loop kept on going before showing the Alert Dialog. Now I have to think of another...
Read more >
Developers - Loop stops after dialog goes away - - Bountysource
Loop stops after dialog goes away. ... I'm trying to show two dialogs, one after the other. In this small example I use...
Read more >
Labview stops execution of one loop when a dialog box is ...
Hello all,. I have a multiple loop program (one loop does data acquisition, one for analysis, and another for error handling).
Read more >
Why doesn't the alert dialog pause a for Each loop?
You just may put an “repeat while” block right after the Alert, that will loop until some variable set by Alert's response will...
Read more >
Close for loop with dialog box and close and open the ... - Reddit
By far the easiest solution is for the VI to open the front panel on entry and have a latching boolean button to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found