I'm developing a UI which has a Run button to run a certain tests on command prompt.I tried implementing threads here for invoking the command prompt and thought of monitoring the thread. Till the tests are run (on command prompt), I want the run button to be disabled and want to enable it only when the command prompt is closed.
I have created a .bat file to run the list of tests in command prompt.
The code is as follows:
Thread for invoking command prompt:
class RunMonitor(threading.Thread):
def run(self):
print 'Invoking the command prompt .....'
subprocess.call(["start", "/DC:\\Scripts", "scripts_to_execute.bat"], shell=True)
For Monitoring the thread
def runscript(self):
print 'Complete_file_Path inside Run script is : ' , self.complete_file_path
file_operation.Generate_Bat_File(self.complete_file_path)
run_monitor_object = RunMonitor()
run_monitor_object.start()
while True:
if run_monitor_object.isAlive():
print 'The thread is still alive....'
else:
print 'The Thread is not alive anymore'
self.run_button.setEnabled(True)
break
From the above example, as soon as i invoke the command prompt, I run a while loop to monitor the status and I expect that the thread would be active as long as the command prompt is invoked and would be dead once I close the command prompt. But in my case, the application just hangs..
Few questions: 1. is this the right way to invoke thread? 2. is this the right way to monitor the status of the thread? 3. is there a better way of handling this ??
Any help towards this would be greatly appreciated.
Thanks.