how to make service "not ready" while it is processing a request?

asked 2021-08-12 02:42:25 -0600

masynthetic gravatar image

I have made a pretty bad mistake in assuming that the 'readiness' described in rclpy client.service_is_ready/client.wait_for_service would be 'not ready' when the service is processing another request, however this does not appear to be the case and I believe it is causing my problem here as the service itself really needs to behave in a synchronous manner and I believe the requests are overlapping because I have been relying on the .wait_for_service method which only seems to wait until the service exists

the service doc does not have any mention or method for setting 'ready' which is what would be the most ideal solution. I know I could use a topic or track the state within the service but would like to avoid these if possible. I would probably even rather rewrite the service in C++ if it would be possible there

edit retag flag offensive close merge delete


Yes - wait_for_service only waits until the service 'exists'.

So if I got it right you are afraid that there is a simultaneous access to the service which is using a resource twice. You could use a Mutex to lock concurrent access in that area. For debugging if it is the case you could use some nonblocking try_lock and if that fails you print an error and know that it actually is happening. You can also define as return from the service something like a BUSY

Webadone gravatar image Webadone  ( 2021-08-12 07:44:03 -0600 )edit

thank you so much for your suggestion. I created a lock on the service callback and while this was a perfect solution to the problem I described and was great to learn, unfortunately it did not solve my problem but it led me understand that 1: the service processes the calls synchronously so the lock isn't really needed, but I do like having it for safety 2: my problem is somewhere else

masynthetic gravatar image masynthetic  ( 2021-08-14 17:54:30 -0600 )edit