Closed DinoFra closed 2 months ago
you need to do a bit more asyncio training. you cannot use asyncio.run that way
Hello, could you give me some tip? Thank you
async def run_client():
client = My_OPC_UA_Client():
await client.create_client()
await client.get_node_ide("id")
if __name__ == "__main__":
asyncio.run(run_client())
Sorry for the screenshots.
I have read about that, the option mentioned only works if i want to run the script as the initial program entry point which doesn't happen.
I think the flow of my code, finishes the first asyncio.run() (when the object is created), i.e. the first event loop is closed, and after goes to the second asyncio.run() to execute the async function "getNodeId". I am not understanding the error.
you need to have only one asyncio loop for the entire session (roughly). in a big application the the loop should be running already. Sounds like you in reality want to write sync code. Use the sync wrapper then
Describe the bug
The process of acquiring a read_data_type() of node stayed stuck and i don't know why. I don't know if it's my dumb approach.
To Reproduce
I have a module python (x.py) that calls the object My_OPCUA_Client, as follow: My Object My_OPCUA_Client. After creating the OPCUA client instance i call from x.py the function getNodeId() which is async, as shown above:
After that, the python interpreter stayed stuck. The result that i obtained is: So, it starts the awaitable coroutine read_data_type() but doesn't return.
Expected behavior
Obtaining the data type of node asynchronously
Version
Python-Version:3.11.5 asyncua:1.0.4 asyncio:1.5.8
Thanks for any help.