Closed Ajinkya-Suranis closed 9 months ago
That is not how async programming works. Try a few python asyncio tutorial first
That is not how async programming works. Try a few python asyncio tutorial first
I've already gone through basic tutorial. My main program is synchronous, and it needs to execute asynchronous coroutines (connect, browse nodes, read values etc) whenever necessary. That's why asyncio.run() is used for execution at those places. I've used similar approach at multiple places in my program (other than opcua) and it works perfectly. My expectation is - Using asyncio.run() should always work in a synchronous program.
use the sync wrapper if your code is sync
use the sync wrapper if your code is sync
asyncio.run() would act like a sync wrapper, if I'm not wrong. Can you suggest an alternative?
Calling async code from sync is not that easy. You need a loop running in a thread. But luckily for you I have done that work and you can use the sync wrappers. Look at the sync examples in repository
Calling async code from sync is not that easy. You need a loop running in a thread. But luckily for you I have done that work and you can use the sync wrappers. Look at the sync examples in repository
Thanks a lot. Being a newbie in asyncio, I didn't quite give a lot of thought in sync->async handling before opening the issue. BTW, the run_until_complete() method of asyncio worked in this case, since it runs event loop till completion.
I've written a simple class to connect to Prosys simulation server and browse tags. Following is the sample code:
As we can see, first the connection is established with server using connect_to_server() method and it waits till completion using asyncio.run(). Then, level 1 children are browsed using browse_level1_nodes() and again asyncio.run() is used to wait for completion. However when the program is run, following exception is raised:
When both connection and node browsing is inside a single function, it works properly.
Expected behavior: Browsing nodes should work after connection is successful, when called one after other.