ZMQ & Thread

Post here to get support
Post Reply
mrmks
Beginner
Posts: 13
Joined: Fri Jun 03, 2016 7:08 pm

ZMQ & Thread

Post by mrmks » Wed Sep 28, 2016 2:54 am

Right now, when I try to run zmqsrvtest, nothing happens.
I was seeing "ZMQ library probably not installed" some times before, but not anymore.

Is ZMQ the 'right' way to add (for example) a logging thread and a control thread to the client side? Is it bad to use the packet dispatcher thread (the main one?) for logging?



marcus
Bitcraze
Posts: 599
Joined: Mon Jan 28, 2013 7:02 pm
Location: Sweden
Contact:

Re: ZMQ & Thread

Post by marcus » Wed Sep 28, 2016 8:01 am

Hi,

The python client API is asynchronous for most things, using callbacks when the communication is done and data is available. The callbacks are made in the context of the threads in the API and should return quickly (i.e no blocking or heavy processing). To see how it should be used have a look at the logging example (or a command example). If you want to block/process then you should queue the data to a separate thread and do it there.

Calling the API from multiple threads should be ok, but it depends a bit on what you call. In the setup-phase you should only connect, set-up etc from one thread. But once you are connected you can set parameters and send control commands from multiple threads.

The ZMQ server isn't made for solving this issue, it's more made to be able to process the data on different physical nodes or easily from different languages (ZMQ has libs for lots of them). Instead of calling the API and getting asynchronous callbacks you will call the ZMQ server to set things up (with request/response) and get notified of asynchronous events (like connection, updated parameters, logging data) with publish on different port.

In order to use the ZMQ server you will need to implement the client (have a look at this example) to make the correct requests and handle the data.

Post Reply