<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">An async function is a coroutine and you would need to run it via Qt threads rather than the usual asyncio.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">For example you can use these libraries</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><a href="https://github.com/hanjinliu/qt-asyncio">https://github.com/hanjinliu/qt-asyncio</a> (simple)</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><a href="https://github.com/altendky/qtrio">https://github.com/altendky/qtrio</a> (more complicated)</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">I don't think a constructor can be async though.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">If you just want the function to run asynchronously, why not just create a qt worker thread. Or if you want</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">to use an async library, find if there is a library that is implemented over trio. A normal async library that runs</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">over asyncio will not work with Qt.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Oct 28, 2023 at 10:55 PM ullix <<a href="mailto:ullix@urkam.de">ullix@urkam.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u>

  

    
  
  <div>
    <p>My PyQt5 app so far runs well. But trying to add functionality
      requiring asyncio results in failure.</p>
    <p>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.</p>
    <div style="color:rgb(59,59,59);background-color:rgb(255,255,255);font-family:"Droid Sans Mono","monospace",monospace;font-weight:normal;font-size:15px;line-height:20px;white-space:pre-wrap"><div><span style="color:rgb(0,16,128)">This is working code of the old app:</span></div><div><span style="color:rgb(0,16,128)">
</span></div><div><span style="color:rgb(0,16,128)">ex</span><span style="color:rgb(59,59,59)">     </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(59,59,59)"> </span><span style="color:rgb(38,127,153)">ggeiger</span><span style="color:rgb(59,59,59)">()            
</span></div><div><span style="color:rgb(59,59,59)">...
</span><span style="color:rgb(0,0,255)">class</span><span style="color:rgb(59,59,59)"> </span><span style="color:rgb(38,127,153)">ggeiger</span><span style="color:rgb(59,59,59)">(</span><span style="color:rgb(38,127,153)">QMainWindow</span><span style="color:rgb(59,59,59)">):</span></div></div>
    <div style="color:rgb(59,59,59);background-color:rgb(255,255,255);font-family:"Droid Sans Mono","monospace",monospace;font-weight:normal;font-size:15px;line-height:20px;white-space:pre-wrap"><span style="color:rgb(59,59,59)">    </span><span style="color:rgb(0,0,255)">def</span><span style="color:rgb(59,59,59)"> </span><span style="color:rgb(121,94,38)">__init__</span><span style="color:rgb(59,59,59)">(</span><span style="color:rgb(0,16,128)">self</span><span style="color:rgb(59,59,59)">):</span><div><span style="color:rgb(59,59,59)">        </span><span style="color:rgb(163,21,21)">"""init the ggeiger class"""</span></div><span style="color:rgb(59,59,59)"></span><span style="color:rgb(59,59,59)">        </span><span style="color:rgb(38,127,153)">super</span><span style="color:rgb(59,59,59)">().</span><span style="color:rgb(121,94,38)">__init__</span><span style="color:rgb(59,59,59)">()</span></div>
    <div style="color:rgb(59,59,59);background-color:rgb(255,255,255);font-family:"Droid Sans Mono","monospace",monospace;font-weight:normal;font-size:15px;line-height:20px;white-space:pre-wrap"><span style="color:rgb(59,59,59)">
</span></div>
    <div style="color:rgb(59,59,59);background-color:rgb(255,255,255);font-family:"Droid Sans Mono","monospace",monospace;font-weight:normal;font-size:15px;line-height:20px;white-space:pre-wrap"><span style="color:rgb(59,59,59)">
</span></div>
    <div style="color:rgb(59,59,59);background-color:rgb(255,255,255);font-family:"Droid Sans Mono","monospace",monospace;font-weight:normal;font-size:15px;line-height:20px;white-space:pre-wrap"><span style="color:rgb(59,59,59)">Adding async and await all the way up to this point works, but with e.g. this (and other attempts) it fails:</span></div>
    <div style="color:rgb(59,59,59);background-color:rgb(255,255,255);font-family:"Droid Sans Mono","monospace",monospace;font-weight:normal;font-size:15px;line-height:20px;white-space:pre-wrap"><span style="color:rgb(59,59,59)"></span>
</div>
    <div style="color:rgb(59,59,59);background-color:rgb(255,255,255);font-family:"Droid Sans Mono","monospace",monospace;font-weight:normal;font-size:15px;line-height:20px;white-space:pre-wrap"><span style="color:rgb(59,59,59)"></span><div><span style="color:rgb(0,16,128)">ex</span><span style="color:rgb(59,59,59)">     </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(59,59,59)"> await </span><span style="color:rgb(38,127,153)">ggeiger</span><span style="color:rgb(59,59,59)">()            
</span></div><div><span style="color:rgb(59,59,59)">...
</span><span style="color:rgb(0,0,255)">class</span><span style="color:rgb(59,59,59)"> </span><span style="color:rgb(38,127,153)">ggeiger</span><span style="color:rgb(59,59,59)">(</span><span style="color:rgb(38,127,153)">QMainWindow</span><span style="color:rgb(59,59,59)">):</span></div><div style="color:rgb(59,59,59);background-color:rgb(255,255,255);font-family:"Droid Sans Mono","monospace",monospace;font-weight:normal;font-size:15px;line-height:20px;white-space:pre-wrap"><span style="color:rgb(59,59,59)">    async </span><span style="color:rgb(0,0,255)">def</span><span style="color:rgb(59,59,59)"> </span><span style="color:rgb(121,94,38)">__init__</span><span style="color:rgb(59,59,59)">(</span><span style="color:rgb(0,16,128)">self</span><span style="color:rgb(59,59,59)">):</span><div><span style="color:rgb(59,59,59)">        </span><span style="color:rgb(163,21,21)">"""init the ggeiger class"""</span></div><span style="color:rgb(59,59,59)"></span><span style="color:rgb(59,59,59)">        </span><span style="color:rgb(38,127,153)">await super</span><span style="color:rgb(59,59,59)">().</span><span style="color:rgb(121,94,38)">__init__</span><span style="color:rgb(59,59,59)">()</span></div>
</div>
    <div style="color:rgb(59,59,59);background-color:rgb(255,255,255);font-family:"Droid Sans Mono","monospace",monospace;font-weight:normal;font-size:15px;line-height:20px;white-space:pre-wrap">I guess it is possible? Any pointers welcome?</div>
    <div style="color:rgb(59,59,59);background-color:rgb(255,255,255);font-family:"Droid Sans Mono","monospace",monospace;font-weight:normal;font-size:15px;line-height:20px;white-space:pre-wrap">
</div>
    <div style="color:rgb(59,59,59);background-color:rgb(255,255,255);font-family:"Droid Sans Mono","monospace",monospace;font-weight:normal;font-size:15px;line-height:20px;white-space:pre-wrap">ullix</div>
    <div style="color:rgb(59,59,59);background-color:rgb(255,255,255);font-family:"Droid Sans Mono","monospace",monospace;font-weight:normal;font-size:15px;line-height:20px;white-space:pre-wrap">
<div style="color:rgb(59,59,59);background-color:rgb(255,255,255);font-family:"Droid Sans Mono","monospace",monospace;font-weight:normal;font-size:15px;line-height:20px;white-space:pre-wrap"><span style="color:rgb(59,59,59)">
</span></div>
</div>
    <p></p>
  </div>

</blockquote></div>