[Python] RuntimeWarning: coroutine <aiortc> was never awaited

Discussão em 'Python' iniciado por Stack, Agosto 2, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to use two Python libraries together: windows-capture and aiortc

    Below is the code in my server.py:

    import asyncio
    from windows_capture import Frame, InternalCaptureControl

    from aiohttp import web
    from aiortc import RTCPeerConnection, RTCSessionDescription

    my_channel = None
    is_my_channel_open = False

    async def offer(request):
    params = await request.json()
    offer = RTCSessionDescription(sdp=params["sdp"], type=params["type"])

    pc = RTCPeerConnection()

    global my_channel
    my_channel = pc.createDataChannel("my_channel")
    @my_channel.on("open")
    def on_open():
    # REFERENCE BELOW
    my_channel.send("Hello from Python aiortc server!")
    # REFERENCE ABOVE
    global is_my_channel_open
    is_my_channel_open = True

    # handle offer
    await pc.setRemoteDescription(offer)
    # send answer
    answer = await pc.createAnswer()
    await pc.setLocalDescription(answer)

    def setup_aiohttp_server():
    app = web.Application()
    app.router.add_post("/offer", offer)
    web.run_app(
    app, host="0.0.0.0", port=8080
    )
    print("This print will never happen")

    def setup_windows_capture():
    # Called Every Time A New Frame Is Available
    @capture.event
    def on_frame_arrived(frame: Frame, capture_control: InternalCaptureControl):
    if is_my_channel_open:
    # PROBLEM AREA BELOW
    my_channel.send("data sent from on_frame_arrived")
    # PROBLEM AREA ABOVE

    print_capture_fps() # This prints the capture FPS once a second to console

    # Starts the capture session
    capture.start()
    print("This print will never happen")

    async def main():
    task1 = asyncio.to_thread(setup_windows_capture)
    task2 = asyncio.to_thread(setup_aiohttp_server)

    await asyncio.gather(task1, task2)

    asyncio.run(main())


    My problem is that I'm trying to call my_channel.send("data sent from on_frame_arrived") in the PROBLEM AREA but it seems to completely break the on_frame_arrived function. Every second, the FPS is printed to console, but after calling this method, the FPS stops and I get this error:

    C:\Users\Dzenis\AppData\Local\Programs\Python\Python313\Lib\site-packages\windows_capture\__init__.py:224: RuntimeWarning: coroutine 'RTCSctpTransport._data_channel_flush' was never awaited
    self.capture.start()
    RuntimeWarning: Enable tracemalloc to get the object allocation traceback


    On the browser, I get "Hello from Python aiortc server!" printed, but I only get "data sent from on_frame_arrived" once, instead of an expected ~60 times per second

    Continue reading...

Compartilhe esta Página