How to cancel a service based on a topic's data?

I am new to ROS and I am working on ROS Basics in 5 Days(Python) Course Project. I created a service which uses a custom message in order to perform a square. The turtlebot though should be stopping and canceling the service whenever it detects an obstacle. So I must subscribe to a topic which will provide me with Laser Scan readings. However, I cannot seem to understand how to implement two callback functions together. Or how to cancel a service upon a condition using data received from a topic.

Hello @victoriam2000 ,

ROS1 services don’t support cancellation or preemption. You should have a look at Actions if you want to do something like this.