Differences between quamash and asyncio event loop + processEvents
See original GitHub issueHello,
I was wondering what would be the implication of using the asyncio event loops for a Qt application instead of quamash Event loop.
We can use asyncio with Qt with the following simple code. The app must be killed to be stopped but you get the point :
async def process_events(qapp):
while True:
await asyncio.sleep(0)
qapp.processEvents()
qapp = QApplication(sys.argv)
loop = asyncio.get_event_loop()
loop.run_until_complete(process_events(qapp))
So what does Quamash brings in terms of compatibility and stability with the Qt system compared to asyncio event loop ? Or is it only about a proof of concept ?
The first thing I can see is that asyncio + modal dialogs does not working easiliy. But I wonder if there are more things to know that I’m not aware of ?
Thanks
Issue Analytics
- State:
- Created 7 years ago
- Comments:21 (16 by maintainers)
Top Results From Across the Web
5.6.1.1. asynchronous programming in python 3
The idea behind async programming in python 3 is to avoid callbacks ... QEventLoop() asyncio.set_event_loop(loop) # set the qt event loop as the...
Read more >harvimt/quamash - Gitter
you could in theory use asyncio/event loops ... if you don't call app.exec_() it can't process events, and your app freezes. Gustavo Goretkin....
Read more >Event Loop — Python 3.11.1 documentation
The event loop is the core of every asyncio application. Event loops run asynchronous tasks and callbacks, perform network IO operations, and run...
Read more >Run Qt and Websockets server in same event loop
app.exec() runs QT's event loop, which you can't do since you have to run asyncio's event loop with run_forever() .
Read more >Integrating insync into a responsive GUI application - Groups.io
processEvents () in an attempt to force the GUI to update itself ... RuntimeError: There is no current event loop in thread 'Dummy-6'....
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
A major difference I didn’t see mentioned here is quamash only working for the main application event loop, i.e. QApplication’s main/UI thread. Meanwhile the “let’s put an event loop in an event loop so you can loop while you loop”-approach actually works for arbitrary QThreads. Sample code:
The sequence to get such a thread to join is thus as follows:
I am using this in the context of QNetworkAccessManager, where I have the ability to retry requests and such things, but I also wanted to avoid the signal/callback-oriented approach, since that tends to get messy fast.
Thus, the actual events driving this and completing futures is the QNetworkReply status slots explicitly setting the results on futures previously created. The event loop of asyncio is only around to resume coroutines as the futures they’re waiting on enter done status.
Ok so I did a fast implementation of the option ( https://github.com/Insoleet/quamash/tree/perfs ) :
This implementation breaks
Executor
tests, and notably the ones aboutsubprocesses
, but it was enough to run the benchmark.It looks a bit better but that still not as good as standard asyncio :
Any idea maybe ?