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

Python's asyncio, and an awaitable signal proposal

XMLWordPrintable

    • Icon: Suggestion Suggestion
    • Resolution: Duplicate
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • None
    • PySide
    • None

      There is a Python module called Quamash which integrates Qt's event loop with asyncio's. With it, you can use Python async/await functions (and any other library using asyncio) in your PySide/PyQt application.
      UPDATE: Another module called asyncqt based on quamash appeared, which apply the same idea but for newer versions of Qt.

      I think it would be pretty cool if, in supported python versions, you could await a signal instead of using connect(callback). Like in this contrived example with the clicked signal on QPushButton, you can do this instead of button.clicked.connect(lambda: print("Button clicked!")):

      async def my_function():
          await button.clicked.future()
          print("Button clicked!")
      

      Under the hood it'd connect a simple callback to the signal that gets disconnected after the future is done.

      For signals that take callbacks that have more than one argument, it'd have to return a tuple that you can unpack like this:

      (foo, bar, baz) = await some_obj.some_signal.future()
      

      I imagine there are more possibilities for asyncio integration, so this issue could be a brainstorming thread for that too. (perhaps a version of Quamash made in C++ for tighter Qt integration could come with PySide?)

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

            Unassigned Unassigned
            empyrical empyrical
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes