kill python listener which opened matplotlib figure [closed]
Hello,
i wrote a visualization with matplotlib in python.
import matplotlib.pyplot as plt
def callback(data):
do something
plt.show()
def listener():
rospy.Subscriber('topic', data, callback)
rospy.spin()
Main function.
if __name__ == '__main__':
# Initialize the node and name it.
rospy.init_node('pylistener', anonymous = True)
# Go to the main loop.
listener()
i want to print my figure. The problem is when he get a message he stop till i close the figure. That is fine. But when i want to close the program with ctrl+c the program crash and i have to close the terminal.
It is possible to kill the node and the python program after i close the figure?
Or what i can do against this crashing? It is really annoying that i have to close the terminal and restart it.
thank you for your help and sry i am new on python
Also, where do you define data?