[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: Cleaner async I/O syntax with Qt
From:       "Kyle Altendorf" <sda () fstab ! net>
Date:       2021-12-20 20:04:00
Message-ID: c567abba-45b5-4a5a-9e16-e6edf9576511 () www ! fastmail ! com
[Download RAW message or body]

You don't just get to start using `async`/`await`.  You have to have a proper event \
loop running your coroutines, such as asyncio, Twisted, or Trio.  Since you are \
working with Qt you need an event loop that can co-exist with the Qt one.

https://github.com/twisted/qt5reactor
https://qtrio.readthedocs.io/en/stable/
https://github.com/CabbageDevelopment/qasync

Sadly, I'm the author for QTrio and the most recently active maintainer for \
qt5reactor and I've got a new job not using neither so they need some love...  and \
the asyncio options get forked every year or two it seems.  But, they can all work \
with Qt5 at least, as far as I know.

Personally, I try to use Qt as a GUI library and other tooling for the rest.  If I \
were writing this personally, I would reach for QTrio and httpx I guess.

Cheers,
-kyle

On Mon, Dec 20, 2021, at 13:20, Patrick Stinson wrote:
> Hello,
> 
> I am using QNetworkAccessManager / QNetworkRequest for my async http requests. I am \
> trying to find a way to wrap these in a cleaner python syntax. My first though was \
> an async context manager, effectively like this: 
> with qt_request('https://google.com') as response:
> # executed later
> print(response.body)
> # executed now
> print("Sent request...")
> 
> I have been reading the docs on async context managers, but haven't gotten the \
> concepts into my head yet. Probably because I don't fully get the async and await \
> keywords yet either. Maybe this is actually counter to the python language spec? 
> Cheers,
> -Patrick


[Attachment #3 (text/html)]

<!DOCTYPE html><html><head><title></title><style \
type="text/css">p.MsoNormal,p.MsoNoSpacing{margin:0}</style></head><body><div>You \
don't just get to start using `async`/`await`.&nbsp; You have to have a proper event \
loop running your coroutines, such as asyncio, Twisted, or Trio.&nbsp; Since you are \
working with Qt you need an event loop that can co-exist with the Qt \
one.<br></div><div><br></div><div><a \
href="https://github.com/twisted/qt5reactor">https://github.com/twisted/qt5reactor</a><br></div><div><a \
href="https://qtrio.readthedocs.io/en/stable/">https://qtrio.readthedocs.io/en/stable/</a><br></div><div><a \
href="https://github.com/CabbageDevelopment/qasync">https://github.com/CabbageDevelopment/qasync</a><br></div><div><br></div><div>Sadly, \
I'm the author for QTrio and the most recently active maintainer for qt5reactor and \
I've got a new job not using neither so they need some love...&nbsp; and the asyncio \
options get forked every year or two it seems.&nbsp; But, they can all work with Qt5 \
at least, as far as I know.<br></div><div><br></div><div>Personally, I try to use Qt \
as a GUI library and other tooling for the rest.&nbsp; If I were writing this \
personally, I would reach for QTrio and httpx I \
guess.<br></div><div><br></div><div>Cheers,<br></div><div>-kyle</div><div><br></div><div>On \
Mon, Dec 20, 2021, at 13:20, Patrick Stinson wrote:<br></div><blockquote type="cite" \
id="qt" style="overflow-wrap:break-word;-webkit-line-break:after-white-space;"><div>Hello,<br></div><div \
class="qt-"><br></div><div class="qt-">I am using QNetworkAccessManager / \
QNetworkRequest for my async http requests. I am trying to find a way to wrap these \
in a cleaner python syntax. My first though was an async context manager, effectively \
like this:<br></div><div class="qt-"><br></div><div class="qt-"><pre \
class="qt-c-mrkdwn__pre" \
style="box-sizing:inherit;margin-top:4px;margin-bottom:4px;padding-top:8px;padding-rig \
ht:8px;padding-bottom:8px;padding-left:8px;line-height:1.50001;font-variant-ligatures: \
none;white-space:pre-wrap;overflow-wrap:break-word;word-break:normal;border-top-left-r \
adius:4px;border-top-right-radius:4px;border-bottom-right-radius:4px;border-bottom-left-radius:4px;color:rgb(55, \
56, 58);orphans:2;widows:2;text-decoration-thickness:initial;--darkreader-inline-color:#e1dcd4;font-family:Monaco, \
Menlo, Consolas, &quot;Courier New&quot;, monospace !important;">with qt_request('<a \
target="_blank" class="qt-c-link" href="https://google.com" rel="noopener noreferrer" \
style="box-sizing:inherit;color:inherit;text-decoration-line:none;text-decoration-thic \
kness:initial;text-decoration-style:initial;text-decoration-color:initial;--darkreader-inline-color:inherit;">https://google.com</a>') \
as response:  # executed later
    print(response.body)
# executed now
print("Sent request...")<br></pre><div class="qt-"><br></div></div><div class="qt-">I \
have been reading the docs on async context managers, but haven't gotten the concepts \
into my head yet. Probably because I don't fully get the async and await keywords yet \
either. Maybe this is actually counter to the python language spec?<br></div><div \
class="qt-"><br></div><div class="qt-">Cheers,<br></div><div \
class="qt-">-Patrick<br></div></blockquote><div><br></div></body></html>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic