Loop stops after dialog goes away
See original GitHub issuePlease 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:
- Created 7 years ago
- Comments:6 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
adding
app.setQuitOnLastWindowClosed(False)
makes everything work correctly.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: