I finally found and answer to this on the Github Issues
Here is an example code of a callback receiving data from 3 topics simultaneously and unsubscribing after 40 messages are received:
#!/usr/bin/env python
import message_filters
import rospy
from sensor_msgs.msg import Image, LaserScan, PointCloud2
def image_cb(depth_img, intensity_img, cloud):
global subs, counter
rospy.loginfo_throttle(1, "Receiving data")
counter += 1
if counter > 40:
rospy.loginfo("100 samples, trying to unsubscribe")
[sub.sub.unregister() for sub in subs]
counter = 0
rospy.init_node("test")
depth_sub = message_filters.Subscriber("/pico_flexx_rear/image_depth", Image)
intensity_sub = message_filters.Subscriber("/pico_flexx_rear/image_mono16",
Image)
cloud_sub = message_filters.Subscriber("/pico_flexx_rear/points",
PointCloud2)
subs = [depth_sub, intensity_sub, cloud_sub]
ts = message_filters.ApproximateTimeSynchronizer(subs, 10, 1)
ts.registerCallback(image_cb)
rospy.spin()
As you see here, one could just iterate over the message_filters.Subscriber variable and call the message_filters.Subscriber.sub.unregister() function in order to unsubscribe.