wxpython 按钮 禁用_wxPython:停止使用wxButton线程

  • Post author:
  • Post category:python


如何通过单击wx按钮停止线程?在

这是我的代码:def startMonitor(self,event):

selectedInterface = self.interfaces_cblist.GetValue()

Publisher().sendMessage((“test”),selectedInterface)

self.Close()

selectInterfaceStr = str(selectedInterface)

if len(selectedInterface) == 0:

noSelect_error = wx.MessageDialog(None,”Please select an interface”,””,wx.OK|wx.ICON_ERROR)

noSelect_error.ShowModal()

else:

monitorStarted = wx.MessageDialog(None,”Monitor on %s started”%selectInterfaceStr,””,wx.OK|wx.ICON_ERROR)

monitorStarted.ShowModal()

self.monitorInterface_button.Disable()

threading.Thread(target=self.camtableDetection,args=(selectInterfaceStr,)).start()

threading.Thread(target=self.dhcpexhaustion,args=(selectInterfaceStr,)).start()

def camtableDetection(self,getInterface):

global interface

interface = str(getInterface)

THRESH=(254/4)

START = 5

def monitorPackets(p):

if p.haslayer(IP):

hwSrc = p.getlayer(Ether).src

if hwSrc not in hwList:

hwList.append(hwSrc)

delta = datetime.datetime.now() – start

if((delta.seconds > START) and ((len(hwList)/delta.seconds) > THRESH)):

print “[*]- Detected CAM Table Attack.”

#camAttackDetected = wx.MessageDialog(None,”Cam Attack Detected”,””,wx.ICON_ERROR)

#camAttackDetected.ShowModal()

hwList = []

start = datetime.datetime.now()

sniff(iface=interface,prn=monitorPackets)

def dhcpexhaustion(self,getInterface):

interface = str(getInterface)

global reqCnt

global ofrCnt

reqCnt = 0

ofrCnt = 0

def monitorPackets(p):

if p.haslayer(BOOTP):

global reqCnt

global ofrCnt

opCode = p.getlayer(BOOTP).op

if opCode == 1:

reqCnt=reqCnt+1

elif opCode == 2:

ofrCnt=ofrCnt+1

print “[*] – “+str(reqCnt)+” Requests, “+str(ofrCnt)+” Offers.”

sniff(iface=interface,prn=monitorPackets)

当我点击一个按钮时,我想停止线程,但不知道怎么做。在

有自行中止技术,但我不知道如何在代码中应用它。在



版权声明:本文为weixin_39986169原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。