Blocking subscriber callback and message buffer size #860
-
I realise that in Python API, the subscriber class will call the callback in a new thread whenever a measurement is received. I could see my callback actually create 8 thread in the background processing the in parallel. Could I control the behaviour such that the callback is blocking? Namely, the callback will not be called concurrently, as the next callback is only run after the previous one returns. Also at the same time, a subscruber message buffer, pretty much like ROS API would be useful. This allow us to compromise between real-time performance and frame drops etc. Reference: |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Or alternatively, an API of controlling how many thread the subscriber callback could use. |
Beta Was this translation helpful? Give feedback.
-
HI @chengguizi , eCAL will internally create one thread per subscriber topic (plus some extra, not 100% sure). However, callbacks for multiple topics may run concurrently, so you will have to synchronize mutliple callbacks yourself. However, maybe in your usecase, using the synchronous "receive" function is a better fit. You can poll for data and also give a timeout (to see if you want to block or not). |
Beta Was this translation helpful? Give feedback.
-
Hi @KerstinKeller Thanks for your quick reply. Now I understand callback runs at single thread. I went to study a bit more. I realise the threading starts once i start doing
This really puzzles me. Could you spot a mistake here?
|
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
HI @chengguizi ,
eCAL will internally create one thread per subscriber topic (plus some extra, not 100% sure).
Your callbacks will be blocking, e.g. if you spend tooo much time in the callback and multiple messages arrive in the meantime, you will loose all but the most recent one. There is no internal eCAL queue.
However, callbacks for multiple topics may run concurrently, so you will have to synchronize mutliple callbacks yourself.
However, maybe in your usecase, using the synchronous "receive" function is a better fit. You can poll for data and also give a timeout (to see if you want to block or not).