[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: Can asyncio be combined with PyQt5?
From: Charles <peacech () gmail ! com>
Date: 2023-10-29 7:54:04
Message-ID: CABthHP9QRBvKqr7vSoY7ULYRvSCm0eDZfHm_-m=4DdAHs3Qoqw () mail ! gmail ! com
[Download RAW message or body]
It might be possible to run python-telegram-bot in a Qt worker thread and
then communicate using Qt signal/slot.
On Sun, Oct 29, 2023 at 2:36 PM ullix <ullix@urkam.de> wrote:
> Thank you, I was afraid of such an answer.
>
> Isn't it of convern that two major developments - PyQt and asyncio -
> exclude each other' use? In particular both of your links seem to suggest
> that a combination is possible.
>
> Rewriting the telegram-bot lib is not an option for me, and asyncio does
> not seem a stringent necessity, as its older version runs without it.
>
> Thanks again
>
> ullix
>
>
> Am 28.10.23 um 18:45 schrieb Charles:
>
> 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@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
>>
>
[Attachment #3 (text/html)]
<div dir="ltr"><div class="gmail_default" \
style="font-family:arial,helvetica,sans-serif;font-size:small">It might be possible \
to run python-telegram-bot in a Qt worker thread and then communicate using Qt \
signal/slot.</div></div><br><div class="gmail_quote"><div dir="ltr" \
class="gmail_attr">On Sun, Oct 29, 2023 at 2:36 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>Thank you, I was afraid of such an answer.</p>
<p>Isn't it of convern that two major developments - PyQt and
asyncio - exclude each other' use? In particular both of your
links seem to suggest that a combination is possible.<br>
</p>
<p>Rewriting the telegram-bot lib is not an option for me, and
asyncio does not seem a stringent necessity, as its older version
runs without it.</p>
<p>Thanks again</p>
<p>ullix</p>
<p> <br>
</p>
<div>Am 28.10.23 um 18:45 schrieb Charles:<br>
</div>
<blockquote type="cite">
<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" \
target="_blank">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" \
target="_blank">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" \
target="_blank">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"> <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>
</div>
</blockquote>
</div>
</blockquote>
</div>
</blockquote></div>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic