Below is my code I am trying to run 3 test cases but the tkinter going to unresponsive state, I tried using threads as well but still facing the same issue and seeing one more error msg "The process cannot access the file because it is being used by another process." and I am not sure if the threads stopping after given duration or not, It seems those are not terminating. can any one check the code and please help.
my code
import threading
from tkinter import *
import time
import random
import os
import datetime
import Test_cases
Tc =Test_cases.Test()
class Blocking():
def __init__(self):
self.window_main = Tk(className='Naren-App',)
self.window_main.geometry("600x300")
Label(self.window_main, text="Stability Tool").place(x=460, y=100, anchor="center")
# adding a label Frame to the Main window
self.Frame_window = LabelFrame(self.window_main, text = 'Test Cases')
self.Frame_window.config(width=400, height=800)
self.Frame_window.place(x=300, y=200, anchor="center")
self.var1 = IntVar()
self.Check_Button_1 = Checkbutton(self.Frame_window, text = "Screen_ON_OFF_Test",variable=self.var1).pack()
self.var2 = IntVar()
self.Check_Button_2 = Checkbutton(self.Frame_window, text = "WWAN_LPM_To_Online",variable=self.var2).pack()
self.var3 = IntVar()
self.Check_Button_3 = Checkbutton(self.Frame_window, text = "Get_Device_State",variable=self.var3).pack()
Label(self.Frame_window, text="Enter Each Test Duration in Sec").pack()
self.Duration = IntVar() # to set default value
self.TestDuration = Entry(self.Frame_window, textvariable=self.Duration).pack()
#submitBtn = Button(self.Frame_window, text="submit", command=lambda:submit(Check_Button_1.get(),Check_Button_2.get(),Check_Button_3.get()))
self.submitBtn = Button(self.Frame_window, text="submit", bg='blue',state=NORMAL,command=self.submit)
self.submitBtn.pack()
#stability
self.Frame_window = LabelFrame(self.window_main, text = 'Stability')
self.Frame_window.config(width=400, height=800)
self.Frame_window.place(x=600, y=200, anchor="center")
self.var4 = IntVar()
self.Test_Name_Check_button = Checkbutton(self.Frame_window, text = "Test_Name",variable=self.var4).pack()
self.var5 = IntVar()
self.NumberOf_Iterations_Check_button = Checkbutton(self.Frame_window, text = "NumberOf_Iterations",variable=self.var5).pack()
self.var6 = IntVar()
self.NumberOf_Hours_Check_button = Checkbutton(self.Frame_window, text = "NumberOf_Hours",variable=self.var6).pack()
self.submitBtn2 = Button(self.Frame_window, text="submit", bg='blue', state =DISABLED,command=self.submit)
self.submitBtn2.pack()
self.window_main.mainloop()
def submit(self):
print("var1: %d,\n var2: %d,\nvar3: %d,\nDuration: %d" % (self.var1.get(), self.var2.get() , self.var3.get(), self.Duration.get()))
TestDuration = int(self.Duration.get())
print("Test Duration2:", TestDuration)
Tc.Duration = TestDuration
print("Passing Duration:", Tc.Duration)
self.submitBtn['bg']='blue'
self.submitBtn['state']=DISABLED
if self.var1.get() == 1 :
print("Starting Screen on off \n")
print("Screen On OFF Test Will run For:",TestDuration ,"sec \n")
T1=threading.Thread(target=Tc.Screen_ON_OFF()).start()
time.sleep(TestDuration+5)
#T1.join()
if self.var2.get() == 1 :
print("Starting LPM to Online \n")
print("LPM to Online Test Will run For:",TestDuration ,"sec \n")
T2=threading.Thread(target=Tc.LPM_To_Online()).start()
time.sleep(TestDuration+5)
if self.var3.get() == 1 :
print("Getting device state \n")
print("Getting device statet Will run For:",TestDuration ,"sec \n")
T1=threading.Thread(target=Tc.Get_Device_State()).start()
time.sleep(TestDuration+5)
return Label(self.window_main, text="Submitted!").pack()
def main():
block = Blocking()
if __name__ == '__main__':
main()