pythonpython-3.xpyside2python-asyncio

Use Qt Pyside2 with asyncio await syntax?


How to await this function (src ) in the main loop of pyside2:

async def do_request(value): #asyncqt maybe possible
    #print("do request")
    await asyncio.sleep(value)
    #print("request finished")
    return value

async def eventFilter(self, source, event): #impossible, needs pyside2 rewrite
     ... 

I am very reluctant to use any nonoffical stuff, so pyside2: i looked into examples of pyside2 having Qthreads examples, but no asyncio await. My lib uses asyncio so how to await in pyside2?

This is a serious issue: The https://github.com/harvimt/quamash/issues/104 does not support pyside2 and https://github.com/gmarull/asyncqt is not maintained. What is the solution?
Please how to integrate such simple call. i fear breaks/bugs on nonmaintained repos


Solution

  • after watching https://www.youtube.com/watch?v=ol5IuJyw-Tg using built in qthread qrunnable qthread to not block main gui thread is way to go.

    for examples see https://code.qt.io/cgit/pyside/pyside-setup.git/tree/examples/corelib and browse the source (its for pyside2)