Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to run async in different thread?
Forum Updated to NodeBB v4.3 + New Features

How to run async in different thread?

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 569 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Igor86
    wrote on 28 Apr 2022, 12:14 last edited by Igor86
    #1

    Hi all,

    this might be a dumb question, please bear with me, i started coding in python just a short time ago.

    I had my code running on a different QThread and it worked great. Now I had to change the API i use inside the function, and this new function requires me to await my function. So i am basically calling an awaited function.

    But when I execute it I get an error:

    RuntimeWarning: coroutine 'cTelegram.sendImage' was never awaited
    self.exec_()

    I call my task like this:

    self.telegramThread = QThread()
           self.telegramWorker = TelethonClass.cTelegram()
           self.telegramWorker.moveToThread(self.telegramThread)
           self.tgSig.tgSignal.connect(self.telegramWorker.sendImage)
           self.telegramThread.start()
    

    and my called code is this:

    class cTelegram(QObject):
       async def sendImage(self, im0, depot, score, classname):
           
           .... some irrelevant suff here...
    
            await bot.send_file(-11111111113, image_stream)
    

    What am I doing wrong?

    Thank you

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 28 Apr 2022, 20:55 last edited by
      #2

      Hi,

      I think the issue here is that you are mixing two different aspects. The async/await parts require an event loop to run but you don't create one and that loop is not the one from Qt either.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      1/2

      28 Apr 2022, 12:14

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved