wxpython thread question
marcinguy at gmail.com
marcinguy at gmail.com
Sun Feb 10 23:26:21 EST 2008
I am new to threading and python. Currently I am working on a GUI app
that will be a frontend to CLI client.
I want to invoke a method of the class from GUI and run it in the
thread. That works well, the problems is I dont know how can I stop
this operation, thread if the user would like to stop/cancel it.
Here is the code:
.
.
.
class ScanThread:
def __init__(self, txtbox, para):
self.para = para
self.txtbox = txtbox
#print "Init"
def Start(self):
self.keepGoing = self.running = True
thread.start_new_thread(self.Run, ())
#print "Start"
def Stop(self):
self.keepGoing = False
#print "Stop"
def IsRunning(self):
return self.running
#print "IsRunning"
def Run(self):
if self.keepGoing:
obj=tool.sanner(self.para,self.txtbox);
obj.scan()
obj.attack()
#time.sleep(1)
self.running = False
#print "Run set to false"
.
.
.
def do_Scan(self, event): # wxGlade: MyFrame.<event_handler>
#print "Event handler `do_Scan' not implemented"
self.threads = []
val = self.text_ctrl_1.GetValue()
box = self.text_ctrl_2;
self.threads.append(ScanThread(box,val))
for t in self.threads:
t.Start()
self.Scan.Enable(False)
self.Stop.Enable(True)
self.frame_1_statusbar.SetStatusText("Scanning")
#event.Skip()
def do_Stop(self, event): # wxGlade: MyFrame.<event_handler>
#print "Event handler `do_Stop' not implemented"
busy = wx.BusyInfo("One moment please, waiting for threads to
die...")
wx.Yield()
for t in self.threads:
t.Stop()
running = 1
while running:
running = 0
for t in self.threads:
running = running + t.IsRunning()
time.sleep(0.1)
#self.Destroy()
#event.Skip()
do_Stop doesn't stop the Thread. Works well if I put the simple code
in the thread (i.e printing text etc), but with CLI class code I am
using, it simply doesn't respond.
Any help and explanation or code sample GREATLY appreciated.
Do I have to rewrite class I am using (CLI client) to work with
threads to make this happen ????
Thanks,
More information about the Python-list
mailing list