3

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

droid192
  • 2,011
  • 26
  • 43
  • 2
    I didn't vote either way, but you can always see the reason if you mouse over the downvote arrow. No one is obliged to give any further explanation than that. – ekhumoro Sep 21 '19 at 19:59
  • 1
    I agree, this is some serious issue, and not an easy one to fix... takes someone with knowledge how to interoperate between different event loops. – nlhnt Oct 30 '22 at 11:49

2 Answers2

1

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)

droid192
  • 2,011
  • 26
  • 43
-1

PyQt is very popular. Though some may not want it because of licensing issues. Whether you choose PyQt or PySide, QTimer has some very nice functionality. In particular, you can use the singleShot() method to run code at a specific delay.

from PySide2.QtCore import QTimer

def myfunc():
    # do your stuff here
    pass

def do_request(self, value):
    # call static function singleShot
    QTimer.singleShot( delay_msec, myfunc)

you can also start() a QTimer to run a task at a regular interval.

bfris
  • 5,272
  • 1
  • 20
  • 37
  • would downvote: not realted to the async await lib and pyside2 is way to go since official. – droid192 Sep 22 '19 at 16:26
  • you're right. there's no asyncio here. i was throwing out QTimer as it has some nice features that you might be able to use instead. – bfris Sep 23 '19 at 05:02