Details
-
Bug
-
Resolution: Duplicate
-
Not Evaluated
-
None
-
6.9
-
None
Description
import asyncio import httpx from PySide6 import QtAsyncio from PySide6.QtWidgets import QApplication, QPushButton, QVBoxLayout, QWidget class MainWindow(QWidget): def __init__(self) -> None: super().__init__() self.fetchButton = QPushButton("fetch") self.fetchButton.clicked.connect(lambda: asyncio.ensure_future(self.fetch())) layout = QVBoxLayout() layout.addWidget(self.fetchButton) self.setLayout(layout) async def fetch(self) -> None: print("start async call") async with httpx.AsyncClient() as client: resp = await client.get("https://httpbin.org/delay/2") print(resp.text) print("end async call") if __name__ == "__main__": app = QApplication() main_window = MainWindow() main_window.show() QtAsyncio.run(handle_sigint=True)
This is the simplest and most frequent scenario of asyncio. Making a network request is definitely one of the most important problems that asyncio should solve. However, this scenario does not work now because some methods are not implemented.
run this code will get
NotImplementedError: QAsyncioEventLoop.create_connection() is not implemented yet
AttributeError: 'QAsyncioTask' object has no attribute '_must_cancel'
If Qt can be organically combined with asyncio, it will have a huge impact on the programming experience of Qt for Python. We will be able to avoid a lot of boilerplate code, whether it is network, database or other asynchronous scenarios.
After some research, I know that the person in charge of this module Adrian Herrmann has left, but I really hope we can move forward with it.
Attachments
Issue Links
- duplicates
-
PYSIDE-2713 QtAsyncio does not support aiohttp
-
- Reported
-