Closed mozesa closed 3 years ago
looks like a missing await statement on asyncua client creation!
async with aio_as_trio(Client("opc.tcp://192.168.0.10:4840/")) as client:
not sure what this does aio_as_trio()
in asyncio it would look like this:
client = Client("opc.tcp://192.168.0.10:4840/")
async with client: #<--- __aenter__ is called here
print("ok")
await asyncio.sleep(1) #mabe trio has something similar !?
I don't think so, it gives me the same error. The problem is what I would like to do is devil. 😈
aio_as_trio()
helps me to be able to call asyncio corotunies within trio loop.
import trio
import trio_asyncio
from asyncua import Client
from trio_asyncio import aio_as_trio
async def async_main():
client = Client("opc.tcp://192.168.0.10:4840/")
async with aio_as_trio(client):
print("OK")
async def test_spawn_system_task():
# async with trio.open_nursery() as nursery:
# nursery.start_soon(async_main)
trio.lowlevel.spawn_system_task(async_main)
await trio.sleep_forever()
if __name__ == "__main__":
trio_asyncio.run(test_spawn_system_task)
it gives me the same error.
off cource its the same error if you never await...
there are not much rules in life instead of the compiler/interpreter is always right!
If it helps, I had this this same error message happen because I was trying to call an asyncio lib (triopg) from a thread pool (thread spawed from to_thread.run_sync).. Something to do with ContextVar or ThreadLocal not properly keeping the asyncio loop instance around I suppose. I worked around it by using a memory channel and never calling trio_asyncio methods directly from threads.
Calling from threads doesn't work because the called code doesn't inherit the context cross-thread. Fixing that is somewhere on Trio's TODO list; trio-asyncio isn't the only package bitten by this.
@oremanj a system task is “outside” the trio-asyncio loop and thus can’t access it
Hello!
The below code throws
AttributeError: 'NoneType' object has no attribute 'run_aio_coroutine'
. I could boil down to that the cause of it istrio.lowlevel.spawn_system_task(async_main)
. When I use anursery
, it does its job fine.Now the question is that it is bug or feature? 😄
Traceback