class Session(list) :
def __init__(self, session_file, laps_sound_file, end_sound_file, autoparse=True) :
self.session_file = session_file
self.laps_sound_file = laps_sound_file
self.end_sound_file = end_sound_file
self.cont_flag = threading.Event()
self.cont_flag.set()
if autoparse : self.parse()
def start(self) :
print("Entrainement Are going to start in : 10 sec\n" * 10)
time.sleep(10)
for action in self :
if not self.cont_flag.is_set() :
print('pause\n' * 10)
self.cont_flag.wait()
os.system('cls')
print(str(action) * 10)
winsound.PlaySound(self.laps_sound_file.split('.')[0], winsound.SND_FILENAME)
time.sleep(action.time)
winsound.PlaySound(self.end_sound_file.split('.')[0], winsound.SND_FILENAME)
def pause(self) :
self.cont_flag.clear()
def cont_session(self) :
self.cont_flag.set()
i have 2 thread in my programm, the first thread is waiting console input and the second thread is executing start methode of class Session
the first thread is acting like a control panel on the session thread, there is the code :
while 1 :
command = input("enter you're command : ").strip().lower()
if command == 'exit' :
break
elif command == 'pause' :
sess.pause()
elif command == 'continue' :
sess.cont_session()
else : print('invalide command, please retry')
so i want to know if i must use a lock between :
if not self.cont_flag.is_set() :
print('pause\n' * 10)
self.cont_flag.wait()
and
def pause(self) :
self.cont_flag.clear()
listis never helpful. It often leads to unexpected, undefined behavior.