dolejska-daniel / amcp-pylib

Python client library for CasparCG's AMCP (Advanced Media Control Protocol).

Home Page:https://pypi.org/project/amcp-pylib/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

asyncio problem

MarcinOsko opened this issue · comments

Hello.
First of all, thank you for your work on your library.
Great to be able to use this tool.
However, I have a problem with your library.
When I use:

from amcp_pylib.core import Client

client = Client()
client.connect('192.168.0.10', 5250)

Everything is OK
but
When I use:

import asyncio
from amcp_pylib.core import ClientAsync

client = ClientAsync()
asyncio.new_event_loop().run_until_complete(client.connect('192.168.0.10', 5250))

i get an error message:

venv/lib/python3.11/site-packages/amcp_pylib/core/connection_async.py:21: RuntimeWarning: coroutine 'ConnectionAsync.connect' was never awaited
  self.connect(address_info[0], address_info[4])
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

I also tried using it as follows however I was getting the same error.

import asyncio
from amcp_pylib.core import ClientAsync

async def connect():
    client = ClientAsync()
    await client.connect('192.168.0.10', 5250)

async def main():
    task = connect()
    try:
        await asyncio.wait_for(task, timeout= 4.0)
    except asyncio.TimeoutError:
        print('Gave up waiting, task canceled')
    except Exception as e:
        print(f'Task failed with: {e}')

asyncio.run(main())