Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asyncio problem #11

Open
MarcinOsko opened this issue Mar 30, 2023 · 0 comments
Open

asyncio problem #11

MarcinOsko opened this issue Mar 30, 2023 · 0 comments

Comments

@MarcinOsko
Copy link

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())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant