• DepthAI-v2
  • [Question] DepthAI DataOutputQueue.addCallback()

Where do callbacks run from `DataOutputQueue.addCallback()`? A new thread? How safe is it to use it in Python? Do we need to use locks?

DataOutputQueue.addCallback() seems like a very useful feature but I think there are only two real uses of it in all the DepthAI GitHub (an example and for handling events).

I think it could use some more love.

Hi @bherbruck !

You are right, they run on a separate thread, and it looks like they use locks; Source here

We also use it in the SDK. Note that the queue should be set to non-blocking, and should have queue size of 1 (anything above is a waste of RAM, as it will fill up anyway).

We don't use it much in examples as it's not called from main thread, so we can't display images (cv2.imshow has to be run on main thread).

Thoughts?
Thanks, Erik

Are there any potential pitfalls to using addCallback()? I guess I'm wondering if it is a different kind of thread as compared to regular python threading.Thread.

Our applications are entirely headless and involve up to 36 OAK PoE devices on a single host. So no cv2.imshow, queues of images and MJPEG server FTW.

We have been slowly fine-tuning the process of handling many devices and reducing the number of infinite loops is preferable.

Hi @bherbruck ,
I think the only thing to keep in mind is that python doesn't offer true parallelism due to GIL, so only 1 thread at a time can be executed, which in some cases also simplifies things.

Right, so are the "threads" created in addCallback() python threads or some other C++ implementation of them?

@bhuvanchandradv

The underlying thread that calls from `addCallback()` comes from C++ (DataOutputQueue reading thread).

AFAIK GIL is locked implicitly as the "call" goes to Python land, as otherwise things would crash.