The QEventLoop class is an implementation of the asyncio event loop that uses the Qt event loop. It allows you to run asynchronous code within a Qt application.
If you are using an existing, already running QApplication, you must instantiate QEventLoop with already_running=True. In this case, you are responsible for manual cleanup using stop() and close().
On Windows, it uses QIOCPEventLoop (Proactor), and on Unix-like systems, it uses QSelectorEventLoop (Selector).
import asyncio
from qasync import QEventLoop
# Example usage with asyncio.run
async def main():
await asyncio.sleep(1)
print("Hello from qasync!")
# Note: In Python 3.12+, run() is simplified.
# For older versions, you might need to provide a loop_factory.
asyncio.run(main(), loop_factory=lambda: QEventLoop(app))