Hi everyone,
i am working on a gui in wxpython where i am trying to execute a file test.py , using a subprocess [ Popen ].Now my gui handles a realtime data.
I am getting much problem in synchronising the thread.My application gets hanged …
please any one guide me …
i am pasting the logic of my code…
class WorkerThread(threading.Thread):
“”"
Create thread and Synchronise the thread execution.
“”"
def __init__(self, window,frequency, period, decimation, whatfunction):
threading.Thread.__init__(self)
self.window = window
self.freq = frequency
self.duration = period
self.decim = decimation
self.whatfunction = whatfunction
self.analyse = "analyse"
self.capture = "capture"
self.timeToQuit = threading.Event()
self.timeToQuit.clear()
self.messageDelay = 0.01
self.capturedfilename = ""
def stop(self):
self.timeToQuit.set()
def run(self):
if self.whatfunction == self.capture:
wx.CallAfter(self.window.LogCaptureMsg, "Capture data from device:\n\n")
cmd = ['./capture.sh "%s" "%s" "%s"' %(self.freq, self.duration, self.decim)]
else:
wx.CallAfter(self.window.LogAnalyseMsg, "Analyse the captured data: \n\n")
cmd = ['./capture.sh 944.4M 10 112']
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
flag = True
while flag == True:
line = proc.stdout.readline()
self.timeToQuit.wait(self.messageDelay)
if self.timeToQuit.isSet():
break
if self.whatfunction == self.capture:
wx.CallAfter(self.window.LogCaptureMsg, line)
else:
wx.CallAfter(self.window.LogAnalyseMsg, line)
if line == "" :
flag = False
else:
if self.whatfunction == self.capture:
wx.CallAfter(self.window.LogCaptureMsg, "\nCapture Process Finish.\n")
wx.CallAfter(self.window.ThreadFinished, self)
else:
wx.CallAfter(self.window.LogAnalyseMsg, "\nAnalysis Process Finish.\n")
wx.CallAfter(self.window.ThreadFinished, self)
***** above is the worker thread , which is called on press of a button . *******
**** this is the main class function of the gui ****
button -> press ->onButtonCapture()
def onButtonCapture(self, evt):
self.count += 1
inputValue = RetreiveValues(self)
(frequency,duration,decimation) = inputValue.GetValues()
if frequency != 0 or duration != 0 or decimation != 0:
thread = WorkerThread( self , frequency, duration, decimation,"capture")
self.threads.append(thread)
#self.UpdateCount()
thread.start()
#thread.join()
#self.StopThreads()
else:
pass
Regards,
Anil ph