Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-3097

Unable to use any network related

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Not Evaluated Not Evaluated
    • None
    • 6.9
    • QtAsyncio
    • None
    • All

      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.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            crmaurei Cristian Maureira-Fredes
            rainzee rainzee wang
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes