2

I am making a radar in python and what I want to do is to make every point detected (plotted on the map) deleted after, let's say, 2 seconds. I am beginner at Python, so I am probably not doing it the best way. I am using Signal module to attach a 'handler' function to the signal that would work as an interrupt after every 2 seconds, saying that 'the oldest' detected point on the plot should be deleted. I am not sure how to delete a point that was plotted, so I just 'colored' it by plotting the same point but in the color of the background :/ I am having my detected points in a 'points' list.

def handler():
         if 0 != len(points):
            ax.plot(points[0][0], points[0][1], color='#8DEEEE')
            points.pop(0)

#Set the signal handler and a 2-second alarm
signal.signal(signal.SIGALARM, handler)
signal.alarm(2)
Nicky Name
  • 101
  • 2
  • 9
  • 1
    `signal.alarm(2)` doesn't set an alarm to send signals every two seconds, but just once after two seconds. but what is your question, actually? – Pavel May 24 '14 at 13:45
  • @Pavel is there a way to make something like a 'ticker' that calls the function attached to it every 2 seconds, in Python? – Nicky Name May 24 '14 at 13:49
  • 1
    http://stackoverflow.com/questions/8600161/executing-periodic-actions-in-python – Pavel May 24 '14 at 13:51

1 Answers1

1

I would question your architecture. Signals are an operating system mechanism mainly for the purpose of inter-process communication. Signals are hard to get right, there are plenty of pitfalls, especially when it comes to which things you are allowed to do in the signal handler. Signals also do not behave the same on different platforms. I am quite sure that for your application you find a more appropriate way for event notification. You might want to use threads (look at the threading module) and queues.

Dr. Jan-Philip Gehrcke
  • 33,287
  • 14
  • 85
  • 130