Can asyncio be combined with PyQt5?

Charles peacech at gmail.com
Sat Oct 28 17:45:41 BST 2023


An async function is a coroutine and you would need to run it via Qt
threads rather than the usual asyncio.

For example you can use these libraries

https://github.com/hanjinliu/qt-asyncio (simple)
https://github.com/altendky/qtrio (more complicated)

I don't think a constructor can be async though.

If you just want the function to run asynchronously, why not just create a
qt worker thread. Or if you want
to use an async library, find if there is a library that is implemented
over trio. A normal async library that runs
over asyncio will not work with Qt.

On Sat, Oct 28, 2023 at 10:55 PM ullix <ullix at urkam.de> wrote:

> My PyQt5 app so far runs well. But trying to add functionality requiring
> asyncio results in failure.
>
> I tried to integrate the telegram-bot function (pip: python-telegram-bot).
> When using the old version 13.15 I got it running, but I am swamped with
> deprecation warning. But the new version 20.6 mandates the use of asyncio,
> and here is where I lack understanding; I can't get it to work.
> This is working code of the old app:
> ex = ggeiger()
> ... class ggeiger(QMainWindow):
> def __init__(self):
> """init the ggeiger class"""
> super().__init__()
> Adding async and await all the way up to this point works, but with e.g.
> this (and other attempts) it fails:
> ex = await ggeiger()
> ... class ggeiger(QMainWindow):
> async def __init__(self):
> """init the ggeiger class"""
> await super().__init__()
> I guess it is possible? Any pointers welcome?
> ullix
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20231028/99821e44/attachment-0001.htm>


More information about the PyQt mailing list