每当有键盘中断时,我都会尝试清空列表,但这不起作用。下面是我的代码。
while 1:
try:
n=0
while n<10:
pkt=sniff(prn=lambda x:x.sprintf("{Ether : %ether.src% --> %ether.dst%}"),timeout=1,store=1)
buffpkt+=pkt[:] ##Store packets in a list buffer
n+=1
self._tempbuffstore(buffpkt)
except KeyboardInterrupt:
buffpkt=[] ##Flush the list asynchronously "THIS IS THE MAIN REQUIREMENT FOR INTERRUPT"
raise
我尝试做所有可能的事情,但这个中断处理程序不起作用。有什么帮助吗?