Closed thomascobb closed 3 years ago
Looks like it, Channel Access Reference:
This function, or ca_attach_context(), should be called once from each thread prior to making any of the other Channel Access calls. If one of the above is not called before making other CA calls then a non-preemptive context is created by default, and future attempts to create a preemptive context for the current threads will fail.
Ok, I guess deferring the context creation until the first time we get a channel is probably a reasonable fix then?
I don't know; can async execution contexts hop threads?
No, this is specifically for the example above, doing the imports at the top of the file, then spawning the camonitor
in the asyncio
thread. It's more because it's too easy to accidentally import aioca
in the wrong thread
Well, clearly the simplest thing is, as you say, defer the context creation. There's still the hazard of somebody running an async excecutor that chooses to hop threads (I presume this is possible) ... but I think we can say it's all their fault if things go wrong!
This doesn't work:
But this does
Doing the
ca_context_create(1)
onget_channel
(i.e. in the correct thread) makes the first bit of code work.@Araneidae does a ca_context only work on the thread it is created in?