Skip to main content
 首页 » 编程设计

python之如何在 Python 中添加处理程序和信号

2025年05月04日9qlqwjy

<分区>

我正在用 python 制作一个雷达,我想做的是让检测到的每个点(绘制在 map 上)在比方说 2 秒后删除。我是 Python 的初学者,所以我可能不是最好的方法。我正在使用 Signal 模块将“处理程序”功能附加到信号上,该功能每 2 秒后将作为中断工作,表示应删除绘图上“最旧”的检测点。我不确定如何删除绘制的点,所以我只是通过绘制相同的点但使用背景颜色来“着色”它:/ 我将检测到的点放在“点”列表中。

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)